I'm working in remote interpreter in VS code. Seems it works well but... I created a folder (module) "utils" with some code. Then I created another module named data_load in there one file 'data_loader.py'. In this file I try to import module from utils. But VScode rise an error that such module is not found. I tried to run same structure in pycharm and it works. Please, help me to solve this problem.
Traceback (most recent call last): File "/workspace/docker-examples/pych/data_load/data_loader.py", line 16, in <module>
from utils.util import XyzTuple, xyz2irc ModuleNotFoundError: No module named 'utils'
This means the parent folder of utils
folder was not in the PYTHONPATH
variable in the VSCode, while it was in it in the PyCharm. You can get the PYTHONPATH
through this:
import sys
from pprint import pprint
pprint(sys.path)
In the VSCode, you can do this to modify the PYTHONPATH
:
Add these in the settings.json file to Modify the PYTHONPATH
in the terminal:
"terminal.integrated.env.windows": { "PYTHONPATH": "xxx/site-packages" }
Create a .env
file under your workspace, and add these settings in it to modify the PYTHONPATH
for the extension and debugger: PYTHONPATH=xxx/site-packages
You can refer to here to understand the effects of these two configurations.
Modify it directly in the python file. Add these codes in the b.py file.
import sys; sys.path.append("xxx/Project/src")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.