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
Related
I'm trying to use opencv module with python.
I have Python3.10.
I installed the module and with the use of Python interpreter in the command line, writing "import cv2" it works fine.
Now, I want to use opencv inside PyCharm.
I went to "File->Settings->Project->Python Interpreter" and then I tried to add the module "opencv-python" but it returned:
"Error occurred when installing package 'opencv-python'. Details.."
and clicking on Details, this is the command output:
Error: Traceback (most recent call last):
File "/opt/pycharm-community-2022.3.1/plugins/python-ce/helpers/packaging_tool.py", line 73, in run_pip
runpy.run_module(module_name, run_name='__main__', alter_sys=True)
File "/usr/lib/python3.9/runpy.py", line 210, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/usr/lib/python3.9/runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/user/Progetti/SottoProgettiPython/RiconoscimentoFacciale/venv/lib/python3.9/site-packages/pip/__main__.py", line 29, in <module>
from pip._internal.cli.main import main as _main
File "/home/user/Progetti/SottoProgettiPython/RiconoscimentoFacciale/venv/lib/python3.9/site-packages/pip/_internal/cli/main.py", line 9, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/home/user/Progetti/SottoProgettiPython/RiconoscimentoFacciale/venv/lib/python3.9/site-packages/pip/_internal/cli/autocompletion.py", line 10, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/home/user/Progetti/SottoProgettiPython/RiconoscimentoFacciale/venv/lib/python3.9/site-packages/pip/_internal/cli/main_parser.py", line 9, in <module>
from pip._internal.build_env import get_runnable_pip
File "/home/user/Progetti/SottoProgettiPython/RiconoscimentoFacciale/venv/lib/python3.9/site-packages/pip/_internal/build_env.py", line 20, in <module>
from pip._internal.cli.spinners import open_spinner
File "/home/user/Progetti/SottoProgettiPython/RiconoscimentoFacciale/venv/lib/python3.9/site-packages/pip/_internal/cli/spinners.py", line 9, in <module>
from pip._internal.utils.logging import get_indentation
File "/home/user/Progetti/SottoProgettiPython/RiconoscimentoFacciale/venv/lib/python3.9/site-packages/pip/_internal/utils/logging.py", line 29, in <module>
from pip._internal.utils.misc import ensure_dir
File "/home/user/Progetti/SottoProgettiPython/RiconoscimentoFacciale/venv/lib/python3.9/site-packages/pip/_internal/utils/misc.py", line 42, in <module>
from pip._internal.locations import get_major_minor_version
File "/home/user/Progetti/SottoProgettiPython/RiconoscimentoFacciale/venv/lib/python3.9/site-packages/pip/_internal/locations/__init__.py", line 67, in <module>
from . import _distutils
File "/home/user/Progetti/SottoProgettiPython/RiconoscimentoFacciale/venv/lib/python3.9/site-packages/pip/_internal/locations/_distutils.py", line 20, in <module>
from distutils.cmd import Command as DistutilsCommand
ModuleNotFoundError: No module named 'distutils.cmd'
I didn't found any working solutions for the module distutils.
I tried to install and reinstall the module "python3.10-distutils" but it is already installed.
Someone knows how to solve the problem?
Thanks in advance,
Marco
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 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
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.