Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError: No module named 'debugpy' #1148

Closed
korompaiistvan opened this issue Dec 9, 2022 · 7 comments
Closed

ModuleNotFoundError: No module named 'debugpy' #1148

korompaiistvan opened this issue Dec 9, 2022 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@korompaiistvan
Copy link

Environment data

  • debugpy version: 1.6.4
  • OS and version: VSCode devcontainer mcr.microsoft.com/devcontainers/python:3.8
  • Python version: 3.8.15
  • Using VS Code or Visual Studio: VSCode 1.74.0 (commit 5235c6bb189b60b01b1f49062f4ffa42384f8c91)

Actual behavior

Debugging Flask apps throws a ModuleNotFoundError, even with a minimal application. This happens both when I use the built-in debugger config, or create my own via launch.json. The terminal output is:

/usr/bin/env /usr/local/bin/python /home/vscode/.vscode-server/extensions/ms-python.python-2022.20.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher 56505 -- /workspaces/debug-repro-folder/main.py

 * Serving Flask app 'main'
 * Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on http://127.0.0.1:5000
Press CTRL+C to quit
 * Restarting with stat
0.17s - Error importing debugpy._vendored.force_pydevd (with sys.path entry: '/home/vscode/.vscode-server/extensions/ms-python.python-2022.20.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/..')
Traceback (most recent call last):
  File "/home/vscode/.vscode-server/extensions/ms-python.python-2022.20.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_defaults.py", line 60, in on_pydb_init
    __import__(module_name)
ModuleNotFoundError: No module named 'debugpy'
 * Debugger is active!
 * Debugger PIN: 499-018-249

This a new phenomenon that I'm only getting with this latest VSCode release.

Expected behavior

Debugging a flask app should not throw an error. While in this minimal case, the debugger and server keep running despite the error, some higher level apps that use Flask under the hood (e.g. Dash) catch this error and stop themselves.

Steps to reproduce:

  1. Clone this repo https://github.com/korompaiistvan/py-debug-repro (alternatively: install py3.8 and flask and just download the main.py file from the repo)
  2. Open VSCode and install the ms-vscode-remote.remote-containers extension (requires Docker to be installed)
  3. Run the "Dev Containers: Rebuild and Reopen in Container" command
  4. Wait for Flask and the extensions to be installed. You might have to reload the window in order for Pylance to stop complaining.
  5. Finally, open up main.py and use the default Python debugger to run it.
@korompaiistvan
Copy link
Author

Downgrading the Python extension to v2022.18.2 fixes the problem

@enzedonline
Copy link

I'm seeing this on my projects since the latest VS Code updates. Python 3.10.6, Python ext v2022.20.0.

Installing debugpy into the venv gives the following error:

\.venv\lib\site-packages\debugpy\_vendored\force_pydevd.py:18: UserWarning: incompatible copy of pydevd already imported: 
...

@int19h
Copy link
Contributor

int19h commented Dec 12, 2022

The spurious "incompatible copy" warning is a separate issue that shows up outside of Docker scenarios; I've created #1149 to track that.

@int19h
Copy link
Contributor

int19h commented Dec 12, 2022

This is due to a mismatch between:

pydevd_defaults.PydevdCustomization.PREIMPORT = '%r;%s' % (
os.path.dirname(os.path.dirname(debugpy.__file__)),
'debugpy._vendored.force_pydevd'
)

and:
try:
sys_path_entry, module_name = PydevdCustomization.PREIMPORT.rsplit(';', maxsplit=1)
except Exception:
pydev_log.exception("Expected ';' in %s" % (PydevdCustomization.PREIMPORT,))
else:
try:
sys.path.insert(0, sys_path_entry)

Note that one side uses %r, so the path will be quoted, but then the other side simply takes everything up to ; and appends it to sys.path, quotes and all.

int19h pushed a commit to int19h/debugpy that referenced this issue Dec 12, 2022
Fix microsoft#1149: UserWarning: incompatible copy of pydevd already imported

Fix formatting for sys.path entry passed to subprocesses.
@int19h int19h closed this as completed in 633597b Dec 13, 2022
@amine-aboufirass
Copy link

I'm experiencing this with Visual Studio 2022 (not vs code), specifically when I attach my debugger to a running python process which contains a subprocess.call. How can I fix this?

@int19h
Copy link
Contributor

int19h commented Apr 7, 2023

Can you please file a separate issue? VS doesn't have multiprocess debugging integrated yet unlike VSCode, and that may be part of the problem in your case. It would also help greatly if you can collect and provide debugpy/pydevd logs - since this is an attach scenario, you should be able to enable them via debugpy --log-to CLI or debugpy.log_to() API.

@amine-aboufirass
Copy link

@int19h it's not working for VS Code either, I logged a separate issue with a reproducible example for that. Please see here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants