I am new to python and attempting to setup up a mono repo using pants as the build system. All has been going well, until I told pants to use a python 3 interpreter by setting in pants.ini
[python-setup]
interpreter_constraints: ["CPython>=3.6.5"]
I have a setup a local library python_library which is imported into a python_binary.
In other words, for an identical code base,
running ./pants run ... on python 2.7 works perfectly
running ./pants run ... with the above interpreter_constraints fails with ModuleNotFoundError
The stack trace I am getting looks like
Traceback (most recent call last):
File "/home/daniel/PycharmProjects/analytics-platform/.pants.d/run/py/CPython-3.6.8/8c5d2b01b2fb9952ae4d6116e537a04edd7039e8/.bootstrap/pex/pex.py", line 397, in execute
exit_code = self._wrap_coverage(self._wrap_profiling, self._execute)
File "/home/daniel/PycharmProjects/analytics-platform/.pants.d/run/py/CPython-3.6.8/8c5d2b01b2fb9952ae4d6116e537a04edd7039e8/.bootstrap/pex/pex.py", line 329, in _wrap_coverage
return runner(*args)
File "/home/daniel/PycharmProjects/analytics-platform/.pants.d/run/py/CPython-3.6.8/8c5d2b01b2fb9952ae4d6116e537a04edd7039e8/.bootstrap/pex/pex.py", line 360, in _wrap_profiling
return runner(*args)
File "/home/daniel/PycharmProjects/analytics-platform/.pants.d/run/py/CPython-3.6.8/8c5d2b01b2fb9952ae4d6116e537a04edd7039e8/.bootstrap/pex/pex.py", line 442, in _execute
return self.execute_entry(self._pex_info.entry_point)
File "/home/daniel/PycharmProjects/analytics-platform/.pants.d/run/py/CPython-3.6.8/8c5d2b01b2fb9952ae4d6116e537a04edd7039e8/.bootstrap/pex/pex.py", line 540, in execute_entry
return runner(entry_point)
File "/home/daniel/PycharmProjects/analytics-platform/.pants.d/run/py/CPython-3.6.8/8c5d2b01b2fb9952ae4d6116e537a04edd7039e8/.bootstrap/pex/pex.py", line 547, in execute_module
runpy.run_module(module_name, run_name='__main__')
File "/usr/lib/python3.6/runpy.py", line 208, in run_module
return _run_code(code, {}, init_globals, run_name, mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/daniel/PycharmProjects/analytics-platform/.pants.d/pyprep/sources/b9e34cbd28ac4d65dc0c5e39ad35ba34da17a128/src/main.py", line 1, in <module>
from str_utils import normalize
ModuleNotFoundError: No module named 'str_utils'
Is there anything I need to add to the pants.ini file when using CPython>=3.6.5?
Please note - the code used works on python2 and python3 when executed manually
Related
I'm running vscode debugger inside Docker container but it started showing an error:
That is very strange because when I open python shell in the same vscode window and import the same module import works just fine. So I need to find the reason why debugger doesn't see the modules
The full error code:
root#854c8a51d1f6:/opt/HonkioServer# python3 entrypoints/api2/docker_entry
Traceback (most recent call last):
File "entrypoints/api2/docker_entry", line 3, in <module>
from index import app
File "/opt/HonkioServer/entrypoints/api2/index.py", line 9, in <module>
from honkio.db.Application import ApplicationModel
ModuleNotFoundError: No module named 'honkio'
root#854c8a51d1f6:/opt/HonkioServer# cd /opt/HonkioServer ; /usr/bin/env /bin/python3 /root/.vscode-server/extensions/ms-python.python-2022.20.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher 39239 -- /opt/HonkioServer/entrypoints/api2/docker_entry
Traceback (most recent call last):
File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/root/.vscode-server/extensions/ms-python.python-2022.20.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/__main__.py", line 39, in <module>
cli.main()
File "/root/.vscode-server/extensions/ms-python.python-2022.20.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 430, in main
run()
File "/root/.vscode-server/extensions/ms-python.python-2022.20.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 284, in run_file
runpy.run_path(target, run_name="__main__")
File "/root/.vscode-server/extensions/ms-python.python-2022.20.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 321, in run_path
return _run_module_code(code, init_globals, run_name,
File "/root/.vscode-server/extensions/ms-python.python-2022.20.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 135, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/root/.vscode-server/extensions/ms-python.python-2022.20.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 124, in _run_code
exec(code, run_globals)
File "/opt/HonkioServer/entrypoints/api2/docker_entry", line 3, in <module>
from index import app
File "/opt/HonkioServer/entrypoints/api2/index.py", line 9, in <module>
from honkio.db.Application import ApplicationModel
ModuleNotFoundError: No module named 'honkio'
My debugger config file launch.json
{
"name": "Python: File",
"type": "python",
"request": "launch",
"program": "/opt/HonkioServer/entrypoints/api2/docker_entry",
"justMyCode": true
}
Finally I found the source of this issue - it was in the file that directly imported to docker-entry file and modules from project directories were imported in a strange way:
# This line adds to modules imports that added below cd two levels up
sys.path.insert(0, os.path.dirname(__file__) + "/../..")
import honkio
However, right after I change this file in vs code, formatter changed lines order automatically placing that line at the bottom of all the other imports. Therefore file imports break and it shows module not found error
I'm trying to teach myself to use the beeware briefcase package for Python, although having issues setting it up. I've got pyenv installed, and my local python version in the root of my project is set to 3.8.9. I'm using windows and Powershell
In PowerShell, I've created the python virtual environment, and have installed briefcase via pip.
I've installed git as well, and linked the repo to github.
When I try to run "briefcase new", and go through the prompts, I receive the following traceback (for both powershell and gitbash):
(I've removed my root details in below errors)
Traceback (most recent call last):
File "C:\~\.pyenv\pyenv-win\versions\3.8.9\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\~\.pyenv\pyenv-win\versions\3.8.9\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\~\CodeProjects\beeware-tutorial\.venv\Scripts\briefcase.exe\__main__.py", line 7, in <module>
File "c:\~\codeprojects\beeware-tutorial\.venv\lib\site-packages\briefcase\__main__.py", line 14, in main
command(**options)
File "c:\~\codeprojects\beeware-tutorial\.venv\lib\site-packages\briefcase\commands\new.py", line 537, in __call__
return self.new_app(template=template, **options)
File "c:\~\codeprojects\beeware-tutorial\.venv\lib\site-packages\briefcase\commands\new.py", line 488, in new_app
cached_template = self.update_cookiecutter_cache(
File "c:\~\codeprojects\beeware-tutorial\.venv\lib\site-packages\briefcase\commands\base.py", line 569, in update_cookiecutter_cache
f"Using existing template (sha {head.commit.hexsha}, "
File "c:\~\codeprojects\beeware-tutorial\.venv\lib\site-packages\git\refs\symbolic.py", line 217, in _get_commit
obj = self._get_object()
File "c:\~\codeprojects\beeware-tutorial\.venv\lib\site-packages\git\refs\symbolic.py", line 210, in _get_object
return Object.new_from_sha(self.repo, hex_to_bin(self.dereference_recursive(self.repo, self.path)))
File "c:\~\codeprojects\beeware-tutorial\.venv\lib\site-packages\git\objects\base.py", line 85, in new_from_sha
oinfo = repo.odb.info(sha1)
File "c:\~\codeprojects\beeware-tutorial\.venv\lib\site-packages\git\db.py", line 43, in info
hexsha, typename, size = self._git.get_object_header(bin_to_hex(binsha))
File "c:\~\codeprojects\beeware-tutorial\.venv\lib\site-packages\git\cmd.py", line 1253, in get_object_header
return self.__get_object_header(cmd, ref)
File "c:\~\codeprojects\beeware-tutorial\.venv\lib\site-packages\git\cmd.py", line 1240, in __get_object_header
return self._parse_object_header(cmd.stdout.readline())
File "c:\~\codeprojects\beeware-tutorial\.venv\lib\site-packages\git\cmd.py", line 1198, in _parse_object_header
raise ValueError("SHA could not be resolved, git returned: %r" % (header_line.strip()))
ValueError: SHA could not be resolved, git returned: b''
Not sure how I managed to fix the issue but I uninstalled git version 2.37.1 and installed git version 2.30.2, used GitBash to create a new environment, and installed a briefcase.
Seems to have solved the issue.
Receving this error while running pylint on my py file
AttributeError: 'Import' object has no attribute 'infer_name_module'
Full trace:
$ pylint some_file.py
Traceback (most recent call last):
File "\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "\Scripts\pylint.exe\__main__.py", line 7, in <module>
File "\lib\site-packages\pylint\__init__.py", line 19, in run_pylint
Run(sys.argv[1:])
File "\lib\site-packages\pylint\lint.py", line 1394, in __init__
linter.check(args)
File "\lib\site-packages\pylint\lint.py", line 801, in check
self._do_check(files_or_modules)
File "\lib\site-packages\pylint\lint.py", line 938, in _do_check
self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
File "\lib\site-packages\pylint\lint.py", line 1018, in check_astroid_module
walker.walk(ast_node)
File "\lib\site-packages\pylint\utils.py", line 1159, in walk
self.walk(child)
File "\lib\site-packages\pylint\utils.py", line 1156, in walk
cb(astroid)
File "\lib\site-packages\pylint\checkers\variables.py", line 1331, in visit_import
module = next(node.infer_name_module(parts[0]))
AttributeError: 'Import' object has no attribute 'infer_name_module'
Not sure for root cause.
pylint version 2.12.2
I'm a pylint maintainer. It's a bug in pylint, could you open an issue, please ? We'd need the code that create the crash if possible.
Edit : it was a bug in an old version of pylint 2.0.2, not 2.12.2
I am trying to use flask dotenv along with python-dotenv but I noticed that there is an inssue on Windwos 10.
Everyting works fine on Mac,Linux but on windows when I run the flask application I get an exception.
It seams that the issue is with the file .flaskenv. If I rename the file from .flaskenv to _flaskenv there is no exception anymore but my env variables are not defined. I have tried to also to load manually this file but without any success. the _flaskenv is not loaded.
# .flaskenv
FLASK_APP=manage.py
FLASK_ENV=development
PS D:\practice\flask-dotenv> flask run
Traceback (most recent call last):
File "C:\Users\popam\AppData\Local\Programs\Python\Python37-32\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\popam\AppData\Local\Programs\Python\Python37-32\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\practice\flask-dotenv\venv\Scripts\flask.exe\__main__.py", line 9, in <module>
File "d:\practice\flask-dotenv\venv\lib\site-packages\flask\cli.py", line 894, in main
cli.main(args=args, prog_name=name)
File "d:\practice\flask-dotenv\venv\lib\site-packages\flask\cli.py", line 548, in main
load_dotenv()
File "d:\practice\flask-dotenv\venv\lib\site-packages\flask\cli.py", line 608, in load_dotenv
dotenv.load_dotenv(path)
File "d:\practice\flask-dotenv\venv\lib\site-packages\dotenv\main.py", line 309, in load_dotenv
return DotEnv(f, verbose=verbose).set_as_environment_variables(override=override)
File "d:\practice\flask-dotenv\venv\lib\site-packages\dotenv\main.py", line 138, in set_as_environment_variables
os.environ[k] = v
File "C:\Users\popam\AppData\Local\Programs\Python\Python37-32\lib\os.py", line 684, in __setitem__
self.putenv(key, value)
ValueError: embedded null character```
When I run mlflow ui the following error occurred:
Traceback (most recent call last):
File "c:\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Anaconda3\Scripts\gunicorn.exe\__main__.py", line 5, in <module>
File "c:\anaconda3\lib\site-packages\gunicorn\app\wsgiapp.py", line 9, in <module>
from gunicorn.app.base import Application
File "c:\anaconda3\lib\site-packages\gunicorn\app\base.py", line 12, in <module>
from gunicorn import util
File "c:\anaconda3\lib\site-packages\gunicorn\util.py", line 9, in <module>
import fcntl
ModuleNotFoundError: No module named 'fcntl'
Traceback (most recent call last):
File "c:\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Anaconda3\Scripts\mlflow.exe\__main__.py", line 9, in <module>
File "c:\anaconda3\lib\site-packages\click\core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "c:\anaconda3\lib\site-packages\click\core.py", line 697, in main
rv = self.invoke(ctx)
File "c:\anaconda3\lib\site-packages\click\core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "c:\anaconda3\lib\site-packages\click\core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "c:\anaconda3\lib\site-packages\click\core.py", line 535, in invoke
return callback(*args, **kwargs)
File "c:\anaconda3\lib\site-packages\mlflow\cli.py", line 131, in ui
mlflow.server._run_server(file_store, file_store, host, port, 1)
File "c:\anaconda3\lib\site-packages\mlflow\server\__init__.py", line 48, in _run_server
env=env_map, stream_output=True)
File "c:\anaconda3\lib\site-packages\mlflow\utils\process.py", line 38, in exec_cmd
raise ShellCommandException("Non-zero exitcode: %s" % (exit_code))
mlflow.utils.process.ShellCommandException: Non-zero exitcode: 1
I used anaconda + python 3.6.5 and I installed git and set path with C:\Program Files\Git\bin\git.exe and C:\Program Files\Git\cmd.
I installed mlflow whit pip install mlflow and its version is 0.2.1.
I set a variable with name GIT_PYTHON_GIT_EXECUTABLE and value C:\Program Files\Git\bin\git.exe in Environment Variables.
How can I solve this?
firstly Uninstall 'mlflow' and 'waitress', then again install 'mlflow' .Now try it works
mlflow documentation already says that
Note 2: We do not currently support running MLflow on Windows.
Despite this, we would appreciate any contributions to make MLflow
work better on Windows.
You're hitting fcntl problem: it's not available on MS Windows platform because it's a "wrapper" around the fcntl function that's available on POSIX-compatible systems. (See https://stackoverflow.com/a/1422436/236007 for more details.)
Solving this requires modifying the source code of mlflow accordingly.