Skip to content

Module import error only when debugging #540

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

Closed
chrissyast opened this issue Feb 4, 2021 · 2 comments
Closed

Module import error only when debugging #540

chrissyast opened this issue Feb 4, 2021 · 2 comments

Comments

@chrissyast
Copy link

chrissyast commented Feb 4, 2021

Environment data

  • debugpy version: Unknown. import debugpy; print(debugpy.__version__) results in 'no module named debugpy'. When debugging through VS Code, shows (\.vscode\extensions\ms-python.python-2021.1.502429796\pythonFiles\lib\python\debugpy\launcher')
  • OS and version: Win 10
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.6.7
  • Using VS Code or Visual Studio: VS Code

My structure

resource.py

class MyAPI():
#some code

main.py

from resource import LettersAPI

launch.json

        {
            "name": "Python: Foo",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "env": {
                "FLASK_APP": "path/to/my/app/main.py",
                "FLASK_ENV": "development",
                "FLASK_DEBUG": "0",
                "PYTHONPATH": "${workspaceRoot}"
            },
            "args": ["run", "--port", "5002"],
            "console": "integratedTerminal"
        },

Steps to reproduce:

  1. Run C:/Python/Python36-7/python.exe "path/to/my/app/main.py" from terminal
  2. Observe working fine
  3. Run Python: Foo debug config

Actual behavior

ModuleNotFoundError: No module named 'resource'

Expected behavior

Debug session starts fine

What I've tried

Adding the python path to env
Adding the file path to "python.autoComplete.extraPaths" (here)

@fabioz
Copy link
Collaborator

fabioz commented Mar 25, 2021

It seems you have an issue in the PYTHONPATH configuration...

Can you provide the information below?

  1. What is your project structure (i.e.: where's your main file, where's your ${workspaceRoot} and where's the resources package.

  2. Run the code below and provide the output you have (in the case where it works as well as the case where it doesn't work).

import sys
print('\n'.join(sorted(sys.path)))

import resource
print(resource)

@fabioz
Copy link
Collaborator

fabioz commented Jun 4, 2021

Closing as additional information wasn't provided.

@fabioz fabioz closed this as completed Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants