'Cannot Import internal modules in VSCode [closed]
I have created internal modules which follow the structure such as follows-
project
└── src
└── rogers
└──__init__.py
└── cd
├── __init__.py
├── preprocessor
└── dataOps
└── __init__.py
└── verint.py
The error I get -
Traceback (most recent call last):
File "main_scripts/PreprocessingStep/verint_preprocessing.py", line 11, in <module>
from rogers.cd.dataOPs import Verint
ImportError: No module named rogers.cd.dataOPs
The init.py in the dataops looks like this
from rogers.cd.dataOPs.boldchat import *
from rogers.cd.dataOPs.verint import *
This is what my setup.py looks like (not showing the entire file, only part of it)
classifiers=[
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
],
install_requires = external_packages,
package_dir={"": "src"},
packages= setuptools.find_namespace_packages(where="src"),
package_data={'': ['*.yaml']},
include_package_data=True,
python_requires=">=3.7",
I recently migrated from PyCharm to VSCode. The code was running fine in PyCharm but doesn't work for VSCode.
Solution 1:[1]
First, add __init__.py file inside the rogers folder.
Then, you need to add your project directory path to sys.path or $PYTHONPATH. Then only python can recognize the package and import it. This will definitely solve the problem.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | rangarajan |
