Description
Environment data
- VS Code version: 1.25.1
- Extension version (available under the Extensions sidebar): 2018.7.0
- OS and version: macOS 10.13.6
- Python version (& distribution if applicable, e.g. Anaconda): 3.7, 3.6 (tested on both)
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.
sample /usr/local/bin/python3 /Users/gojha/Documents/sample/package_1/module_1.py
Traceback (most recent call last):
File "/Users/gojha/Documents/sample/package_1/module_1.py", line 1, in <module>
from package_2.module_2 import hello_world
ModuleNotFoundError: No module named 'package_2'
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 the Output
panel (View
→Output
, change the drop-down the upper-right of the Output
panel to Python
)
Starting Jedi Python language engine.
##########Linting Output - pylint##########
--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
##########Linting Output - pylint##########
--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
##########Linting Output - pylint##########
--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
##########Linting Output - pylint##########
--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
Output from Console
under the Developer Tools
panel (toggle Developer Tools on under Help
)
log.ts:159 INFO no standard startup: panel is active