Skip to content

Unresolved imports #8337

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
nickcorona opened this issue Nov 1, 2019 · 3 comments
Closed

Unresolved imports #8337

nickcorona opened this issue Nov 1, 2019 · 3 comments
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@nickcorona
Copy link

nickcorona commented Nov 1, 2019

The python extension doesn't manage path correctly.

Example project

project
   src
      config.py
      scoring
         scoring.py

Importing config.py from scoring.py with from src import config.py doesn't work. It will return the following error:
ModuleNotFoundError: No module named 'src'

I know other people at work with the exact same issue. And we've not been able to come up with a solution other than adding the project absolute path the settings.json file (which I feel you shouldn't have to do to run a script).

@nickcorona nickcorona added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Nov 1, 2019
@brettcannon
Copy link
Member

This is best asked on Stack Overflow, but in this specific case you need to set PYTHONPATH for Python to know your code exists in src. People often solve this using an environment variable definition file.

If you would like us to try to automatically handle this case for you then you can 👍 #924.

@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Nov 4, 2019
@nickcorona
Copy link
Author

nickcorona commented Nov 5, 2019

I've added an environment variable definition for PYTHONPATH specifying the absolute path to the project directory in .env which is in the root project folder. I reloaded the workspace and the Run Python file in terminal button still can't find src. The issue should be re-opened because it seems like an issue with the extension.

I do not have the same issue if I run lines of code with Shift + Enter or hitting F5.

This is the button I'm talking about:
image

@brettcannon
Copy link
Member

@nickcorona ah, so you're saying the Run Python button doesn't include what's in the .env file when it runs? Then that's a different issue then what you initially asked about, so please open a new issue and please make sure to fill in the issue template.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

2 participants