I used python package managers (PyFlow/PDM) which supports PEP582: packages are installed in the local directory {workspace_path}/__pypackages__/.
I added some configs in settings.json to let VSCode know how to find the packages:
{
...,
"python.autoComplete.extraPaths": [
"__pypackages__/3.7lib"
],
"python.analysis.extraPaths": [
"__pypackages__/3.7/lib"
]
}
I wrote some code, and the completion and inline code docs works well with above settings.
# main.py
#%% jupyter cell
import sys
print(sys.path)
import pandas as pd
print(pd.__version__)
#%%
print("hello world")
I ran my main.py in both ways:
ctrl + opt + N)shift + enter). VSCode asked me to install ipykernel at the first time, but it installed with pip, and not installed into __pypackages__.but it failed and showed: ModuleNotFoundError: No module named 'pandas'.
I check the search path with sys.path, it doesn't contain __pypackages__ for python modules:
['{$HOME}/{workspace}',
'{$HOME}/.vscode/extensions/ms-toolsai.jupyter-2021.5.745244803/pythonFiles',
'{$HOME}/.vscode/extensions/ms-toolsai.jupyter-2021.5.745244803/pythonFiles/lib/python',
'{$HOME}/.pyenv/versions/3.7.10/lib/python37.zip',
'{$HOME}/.pyenv/versions/3.7.10/lib/python3.7',
'{$HOME}/.pyenv/versions/3.7.10/lib/python3.7/lib-dynload',
'',
'{$HOME}/{workspace}/.venv/lib/python3.7/site-packages',
'{$HOME}/{workspace}/.venv/lib/python3.7/site-packages/IPython/extensions',
'{$HOME}/.ipython']
My questions:
settings.json to add search paths (__pypackages__/3.7lib) for Python modules.settings.json to let VSCode Jupyter server launch IPython with ipykernel installed in __pypackages__/3.7lib"python.autoComplete.extraPaths": [
"${workspaceFolder}/__pypackages__/<major.minor>/lib"
],
"python.analysis.extraPaths": [
"${workspaceFolder}/__pypackages__/<major.minor>/lib"
],
Try this in settings.json
Replace <major.minor> with your python version like 3.10, 3.9, etc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With