high-egg-2153
12/30/2020, 8:51 PM./pants run accounts_report/app.py
I am getting the following error:
from pkg_resources import get_distribution, parse_version
ModuleNotFoundError: No module named 'pkg_resources'
Some details:
Python 3.8.6
pip 19.3.1
Manjaro Linux
Any help would be greatly appreciated.enough-analyst-54434
12/30/2020, 8:54 PMpkg_resources
is provided by `setuptools`(https://pypi.org/project/setuptools/) which you probably already knew. In order to resolve that dependency, Pants requires a small bit of setup - namely you have to tell Pants the version of setuptools you want. More here: https://www.pantsbuild.org/docs/python-third-party-dependencies
Before going further, let me know how much of this you already have setup / think you have setup.high-egg-2153
12/30/2020, 8:57 PMenough-analyst-54434
12/30/2020, 8:57 PMhigh-egg-2153
12/30/2020, 8:58 PMenough-analyst-54434
12/30/2020, 8:59 PMenough-analyst-54434
12/30/2020, 9:00 PMsetuptools==???
line. And then, if you look a little lower on that page, you need a module mapping, so - in the sibling BUILD file to requirements.txt you need:
python_requirements(
module_mapping={
"setuptools": ["pkg_resources"]
},
)
high-egg-2153
12/30/2020, 9:00 PMenough-analyst-54434
12/30/2020, 9:01 PMsetuptools
and pkg_resources
top-level packages.enough-analyst-54434
12/30/2020, 9:02 PMhigh-egg-2153
12/30/2020, 9:03 PMpython_requirements(
module_mapping={
"setuptools": ["pkg_resources"]
},
)
and
setuptools==51.1.1
These are at the rootenough-analyst-54434
12/30/2020, 9:04 PMhigh-egg-2153
12/30/2020, 9:04 PMhigh-egg-2153
12/30/2020, 9:05 PMenough-analyst-54434
12/30/2020, 9:05 PMhigh-egg-2153
12/30/2020, 9:07 PMpex_binary(
sources=["app.py"],
entry_point='<http://accounts_report.app|accounts_report.app>',
dependencies=[
':accounts_report_lib',
],
)
python_library(
name="accounts_report_lib"
)
python_tests(name = 'tests')
enough-analyst-54434
12/30/2020, 9:08 PMenough-analyst-54434
12/30/2020, 9:09 PMenough-analyst-54434
12/30/2020, 9:11 PMenough-analyst-54434
12/30/2020, 9:12 PMhigh-egg-2153
12/30/2020, 9:12 PMenough-analyst-54434
12/30/2020, 9:12 PMhigh-egg-2153
12/30/2020, 9:13 PMenough-analyst-54434
12/30/2020, 9:15 PMenough-analyst-54434
12/30/2020, 9:15 PMhigh-egg-2153
12/30/2020, 9:16 PMenough-analyst-54434
12/30/2020, 10:03 PMhundreds-father-404
12/30/2020, 10:04 PMhigh-egg-2153
12/30/2020, 10:27 PMhundreds-father-404
12/30/2020, 10:31 PM./pants dependencies --transitive path/to/app.py
please? Or whichever file has the pkg_resources
importhigh-egg-2153
12/30/2020, 10:31 PMaccounts_report:SQLAlchemy
accounts_report:dash
accounts_report:dash-table
accounts_report:pandas
accounts_report:requirements.txt
high-egg-2153
12/30/2020, 10:33 PMdash>=1.18.1
dash-table>=4.11.1
pandas>=1.1.5
SQLAlchemy>=1.3.22
setuptools==51.1.1
high-egg-2153
12/30/2020, 10:33 PMpython_requirements(
module_mapping={
"setuptools": ["pkg_resources"]
},
)
pex_binary(
sources=["app.py"],
entry_point='<http://accounts_report.app|accounts_report.app>',
)
python_tests(name = 'tests')
hundreds-father-404
12/30/2020, 10:35 PMaccounts_report:setuptools
to the dependencies
for the pex_binary
target and rerun your test? That will confirm this is solely an issue with dependency inference not being picked uphigh-egg-2153
12/30/2020, 10:37 PM./pants dependencies --transitive accounts_report/app.py
accounts_report:SQLAlchemy
accounts_report:dash
accounts_report:dash-table
accounts_report:pandas
accounts_report:requirements.txt
accounts_report:setuptools
high-egg-2153
12/30/2020, 10:38 PM18:37:58.11 [INFO] Completed: Building requirements.pex with 5 requirements: SQLAlchemy>=1.3.22, dash-table>=4.11.1, dash>=1.18.1, pandas>=1.1.5, setuptools==51.1.1
Traceback (most recent call last):
File "/home/greg/Work/foo/foo/.pants.d/tmpsnbrvmgu/accounts_report.pex/.bootstrap/pex/pex.py", line 487, in execute
File "/home/greg/Work/foo/foo/.pants.d/tmpsnbrvmgu/accounts_report.pex/.bootstrap/pex/pex.py", line 404, in _wrap_coverage
File "/home/greg/Work/foo/foo/.pants.d/tmpsnbrvmgu/accounts_report.pex/.bootstrap/pex/pex.py", line 435, in _wrap_profiling
File "/home/greg/Work/foo/foo/.pants.d/tmpsnbrvmgu/accounts_report.pex/.bootstrap/pex/pex.py", line 543, in _execute
File "/home/greg/Work/foo/foo/.pants.d/tmpsnbrvmgu/accounts_report.pex/.bootstrap/pex/pex.py", line 645, in execute_entry
File "/home/greg/Work/foo/foo/.pants.d/tmpsnbrvmgu/accounts_report.pex/.bootstrap/pex/pex.py", line 653, in execute_module
File "/usr/lib/python3.8/runpy.py", line 210, in run_module
return _run_code(code, {}, init_globals, run_name, mod_spec)
File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/greg/Work/foo/foo/.pants.d/tmpsnbrvmgu/./accounts_report/app.py", line 12, in <module>
import dash_bootstrap_components as dbc
ModuleNotFoundError: No module named 'dash_bootstrap_components'
high-egg-2153
12/30/2020, 10:39 PM./pants run accounts_report
high-egg-2153
12/30/2020, 10:41 PMhundreds-father-404
12/30/2020, 10:42 PMdash-bootstrap-components
to your requirements.txt
so that the python_requirements()
call sets that up as a top-level requirement, then dependency inference can do its thing
I’m not sure what’s going on with setuptools
, as it’s worked in many other repos, including Pants. I’m trying to think of why here might be different. Your BUILD file looks goodhigh-egg-2153
12/30/2020, 10:43 PMhundreds-father-404
12/30/2020, 10:45 PMpython_requirements
thing is a macro that creates one distinct python_requirement_library
per each entry in your requirements.txt, which you can confirm by running ./pants list ::
to see every target you have in your project
Pants will notice requirements.txt has changed and recreate the mapping of module names to which code it comes from. You can check by running ./pants dependencies path/to/app.py
or ./pants dependencies --transitive path/to/app.py
high-egg-2153
12/30/2020, 10:46 PMhundreds-father-404
12/30/2020, 10:48 PMaccounts_report:dash-bootstrap-components
show up in ./pants list ::
?high-egg-2153
12/30/2020, 10:48 PMhundreds-father-404
12/30/2020, 10:49 PM./pants --no-pantsd
to avoid memoization and force the module mapping to be recreatedhigh-egg-2153
12/30/2020, 10:49 PMhigh-egg-2153
12/30/2020, 10:51 PMhigh-egg-2153
12/30/2020, 10:55 PMModuleNotFoundError: No module named 'pymysql'
hundreds-father-404
12/30/2020, 10:56 PMhigh-egg-2153
12/30/2020, 10:56 PMhigh-egg-2153
12/30/2020, 10:56 PMSQLAlchemy>=1.3.22
high-egg-2153
12/30/2020, 10:57 PMhigh-egg-2153
12/30/2020, 10:57 PMhundreds-father-404
12/30/2020, 11:02 PMpython_req.project_name.lower().replace("-", "_")
, where python_req
is a Requirement
from pkg_resources
. Meaning, it would convert to sqlalchemy
hundreds-father-404
12/30/2020, 11:02 PM./pants dependencies path/to/app.py
. Is that no longer the case?high-egg-2153
12/30/2020, 11:04 PMhundreds-father-404
12/30/2020, 11:05 PMThe modules are mixed case namesWhat do you mean by this? Your import statements are mixed case?
high-egg-2153
12/30/2020, 11:05 PM/usr/bin/python3.8: No module named accounts_report.__main__; 'accounts_report' is a package and cannot be directly executed
high-egg-2153
12/30/2020, 11:06 PMPyMySQL>=0.10.1
high-egg-2153
12/30/2020, 11:06 PMpymysql>=0.10.1
high-egg-2153
12/30/2020, 11:07 PMpex_binary(
sources=["app.py"],
entry_point='<http://accounts_report.app|accounts_report.app>',
dependencies=[
"accounts_report:setuptools",
":sqlalchemy",
":pymysql"
]
)
hundreds-father-404
12/30/2020, 11:08 PM__init__.py
file, but I’m not certainhigh-egg-2153
12/30/2020, 11:09 PMhigh-egg-2153
12/30/2020, 11:09 PM___init___.py
high-egg-2153
12/30/2020, 11:12 PMhundreds-father-404
12/30/2020, 11:14 PMhigh-egg-2153
12/30/2020, 11:15 PMhappy-kitchen-89482
12/31/2020, 6:52 PMhundreds-father-404
01/04/2021, 9:37 PM/usr/bin/python3.8: No module named accounts_report.__main__; ‘accounts_report’ is a package and cannot be directly executedIs caused by this line:
if __name__ == '__main__':
my_dash_app.run_server(debug=True)
Setting debug=False
. @happy-kitchen-89482 saw a similar issue with Django, that Django’s file watcher did not play nicely with Pex and Pants. Dash is a wrapper around Flask, and debug=True
turns on Flask’s file watcherhappy-kitchen-89482
01/04/2021, 9:47 PM./pants run
for reasons I'm not yet clear on.happy-kitchen-89482
01/04/2021, 9:48 PM./pants run
itself to restart the process on file changeshappy-kitchen-89482
01/04/2021, 9:48 PMpantsd
already watches the filesystem, there's no need for the debug server to do so as wellhundreds-father-404
01/04/2021, 9:48 PMwhich doesn’t play nicely with ./pants run for reasons I’m not yet clear on.I think it’s more an issue with Pex than with
./pants run
. Note that it still fails if doing ./pants package
then dist/path/app.pex
high-egg-2153
01/05/2021, 5:46 PMdash_app.run_server(debug=True)
I get the error mentioned above. If I run like this:
dash_app.run_server(debug=True, use_reloader=False)
Then everything starts fine. So perhaps a little more evidence that file watching or hot reloading is what is causing the issue for me.hundreds-father-404
01/13/2021, 4:42 PM