I have organized my self-written Python scripts within a tree of several sub-directories,
starting from the parent directory "Scripts" which is already included in "python.autoComplete.extraPaths"
within the settings-json:
"python.autoComplete.extraPaths": ["/home/andylu/Dokumente/Allgemeines_material/Sonstiges/Programming/Python/Scripts",
"/home/andylu/anaconda3/lib/python3.7/site-packages"]
Apart from that, I've included a Python environment-file:
"python.envFile": "/home/andylu/Dokumente/Allgemeines_material/Sonstiges/Programming/Visual_studio_code/vscode_own_scripts.env"
which contains the line
export PYTHONPATH=/home/andylu/Dokumente/Allgemeines_material/Sonstiges/Programming/Python/Scripts:/home/andylu/anaconda3/lib/python3.7/site-packages
All of this worked out great before, where all my scripts were distributed just over 1 single directory level, like so:
+---Scripts
| +---General
| | +---script_one.py
| | +---script_two.py
When I imported within any python-script e.g. script_one.py
,
I started the script with
import sys
sys.path.append(
"/home/andylu/Dokumente/Allgemeines_material/Sonstiges/Programming/Python/Scripts/"
)
import General.script_one as one
and pylint recognized this imported script correctly without throwing the aforementioned VS Code pylint(import-error)
.
Now, the situation is different. The scripts had become so many, that I split up the subfolder General
to contain an additional sub-directory level in order to get the scripts organized more lucidly:
+---Scripts
| +---General
| | +---Plotting
| | | +---script_one.py
| | | +---script_two.py
| | +---Misc
| | | +---script_three.py
| | | +---script_four.py
....
When starting a Python script with e.g. the following lines, I get the VS Code pylint(import-error)
for each of following imports.
# Package importing
import sys
sys.path.append(
"/home/andylu/Dokumente/Allgemeines_material/Sonstiges/Programming/Python/Scripts/"
)
import General.Plotting.auxiliary_plotting_functions as aux_plot
import General.Plotting.plotting as plot
#%%
# TIME MEASUREMENT for the entire code/function
import General.Misc.timing
I don't know why pylint stopped recognizing the imports all of the sudden, just because I added an additional sub-directory level. I would like these senseless pylint import errors to disappear, since effectively the subsub-models are being imported correctly when executing the codes.
I even tried to modify the .pylintrc
- file, which lies under
/home/andylu/anaconda3/pkgs/pylint-2.3.1-py37_0/lib/python3.7/site-packages/pylint/test/regrtest_data/.pylintrc
:
[MASTER]
optimize-ast=no
init-hook='import sys; sys.path.append("/home/andylu/Dokumente/Allgemeines_material/Sonstiges/Programming/Python/Scripts")'
Adding the init-hook
- line had no effect either.
__init__.py
- file in all sub- and subsub-directories, even in the main directory "Scripts". So that cannot be it. As for your second point, you refer to removing theanaconda3/../site-packages
- path from the"python.autoComplete.extraPaths"
since these site-packages are already included in my"python.envFile"
? – Cagey