-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
.env file not working. Workspace dir not scanned for modules by default. #2206
Comments
Can you provide the |
The .env file just contained one line.
|
Can you verify, @d3r3kk ? |
I can run this in the debugger, but I cannot run it in the terminal. Also, I could not run it in the shell without VSCode unless I would set the PYTHONPATH accordingly. Run from the debugger:dekeeler@dek-laptop-lnx:~/dev/github/d3r3kk/test/2206_packages_mishap$ cd /home/dekeeler/dev/github/d3r3kk/test/2206_packages_mishap ; env "PYTHONPATH=/home/dekeeler/dev/github/d3r3kk/test/2206_packages_mishap:/home/dekeeler/.vscode-insiders/extensions/ms-python.python-2018.8.0/pythonFiles/experimental/ptvsd" "PYTHONIOENCODING=UTF-8" "PYTHONUNBUFFERED=1" /opt/python/pyenv/versions/3.7-dev/bin/python -m ptvsd --host localhost --port 33709 /home/dekeeler/dev/github/d3r3kk/test/2206_packages_mishap/package_1/module_1.py
sys.version_info(major=3, minor=7, micro=0, releaselevel='final', serial=0)
Hello world! Run from the terminal:dekeeler@dek-laptop-lnx:~/dev/github/d3r3kk/test$ /opt/python/pyenv/versions/3.7-dev/bin/python /home/dekeeler/dev/github/d3r3kk/test/2206_packages_mishap/package_1/module_1.py
Traceback (most recent call last):
File "/home/dekeeler/dev/github/d3r3kk/test/2206_packages_mishap/package_1/module_1.py", line 1, in <module>
from package_2.module_2 import hello_world
ModuleNotFoundError: No module named 'package_2' Note: Indeed, when I run from my bash shell without VSCode running, if I set the dekeeler@dek-laptop-lnx:~/dev/github/d3r3kk/test/2206_packages_mishap$ PYTHONPATH="/home/dekeeler/dev/github/d3r3kk/test/2206_packages_mishap" python package_1/module_1.py
sys.version_info(major=2, minor=7, micro=15, releaselevel='candidate', serial=1)
Hello world! Test code: |
Closing as a duplicate of #944 |
@brettcannon pycham supports this feature. Uusers would expect similar behavior in VSC. Isn't it too early to close this issue #944? |
@DonJayamanne reopened the other issue to discuss with Dan. |
Environment data
Actual behavior
Modules defined in the current workspace folder cannot be imported. The .env file made in the workspace dir has no effect.
Expected behavior
The modules which are created as part of a project must be read, if not automatically by default then through some setting which can be enabled.
Steps to reproduce:
I have a very simple project structure as shown.

From within package_1.module_1, I am trying to import package_2.module_2. And the error which is thrown is as shown.
As per the documentation available, I created a .env file in the workspace folder ('sample' in this case), and then added the PYTHONPATH environment variable there, pointing to the source code ('/Users/gojha/Documents/sample' here). But running the python module stills sees the same error. This is getting really weird now, as I can't find any trace anywhere of how this is actually supposed to work, so that I could validate whether what I am doing is correct.
(If there is some problem in the configuration above, let me know)
Compared to VS Code, other IDEs like PyCharm run such sample code without any configuration problems. What I noticed was that PyCharm before running the module, appends the source folder to sys.path, thus these problems are not faced.
It would be great if something similar could be done for VS Code as well.
Logs
Output for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)Output from
Console
under theDeveloper Tools
panel (toggle Developer Tools on underHelp
)The text was updated successfully, but these errors were encountered: