我在pyenv中安装了两个版本的 python ,python3.7.5 和 3.8.6。我通常使用python3.8.6,所以它是全局激活的(pyenv global 3.8.6
)。
我还在python3.8.6中安装了pipxpip install pipx
来全局安装jupyter lab(pipx install jupyterlab
),它位于~/.local/pipx/venvs/jupyterlab
.
似乎预装了一个 jupyter 内核。
$ jupyter kernelspec list
Available kernels:
python3 ~/.pyenv/versions/3.8.6/share/jupyter/kernels/python3
当我执行时jupyter lab
,会自动选择这个内核。但是,在jupyter lab中,我无法导入安装在 python3.8.6 中的 numpy 。
[1]: import numpy as np
[1]: ---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-0aa0b027fcb6> in <module>
----> 1 import numpy as np
ModuleNotFoundError: No module named 'numpy'
这可能是由于 PATH 设置。
[2]: import sys
sys.path
[2]: ['~/',
'~/.pyenv/versions/3.8.6/lib/python38.zip',
'~/.pyenv/versions/3.8.6/lib/python3.8',
'~/.pyenv/versions/3.8.6/lib/python3.8/lib-dynload',
'',
'~/.local/pipx/venvs/jupyterlab/lib/python3.8/site-packages',
'~/.local/pipx/shared/lib/python3.8/site-packages',
'~/.local/pipx/venvs/jupyterlab/lib/python3.8/site-packages/IPython/extensions',
'~/.ipython']
~/.pyenv/versions/3.8.6/lib/python3.8/site-packages
应该在sys.path
. 为什么不包括此路径?