【发布时间】:2021-05-02 21:27:48
【问题描述】:
我使用了支持PEP582的python包管理器(PyFlow/PDM):包安装在本地目录{workspace_path}/__pypackages__/中。
我在settings.json 中添加了一些配置,让 VSCode 知道如何找到包:
{
...,
"python.autoComplete.extraPaths": [
"__pypackages__/3.7lib"
],
"python.analysis.extraPaths": [
"__pypackages__/3.7/lib"
]
}
我写了一些代码,完成和内联代码文档在上述设置下效果很好。
# main.py
#%% jupyter cell
import sys
print(sys.path)
import pandas as pd
print(pd.__version__)
#%%
print("hello world")
我以两种方式运行我的main.py:
- 使用 VSCode (
ctrl + opt + N) 运行文件 - 运行jupyter cell with ipykernel (
shift + enter)。 VSCode第一次让我安装ipykernel,但是它安装了pip,并没有安装到__pypackages__。
但它失败并显示:ModuleNotFoundError: No module named 'pandas'。
我用sys.path检查搜索路径,它不包含python模块的__pypackages__:
['{$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']
我的问题:
- 如何配置
settings.json为 Python 模块添加搜索路径 (__pypackages__/3.7lib)。 - 如何配置
settings.json让VSCode Jupyter 服务器在__pypackages__/3.7lib中安装ipykernel 启动IPython
【问题讨论】:
标签: visual-studio-code vscode-settings pep