【问题标题】:Jupyter not recognising numpy (using homebrew pyenv)Jupyter 无法识别 numpy(使用自制 pyenv)
【发布时间】:2020-09-07 09:02:48
【问题描述】:

我按照these 的说明获得了一个在 Jupyter Notebook 中工作的 python 虚拟环境(由 pyenv 管理)。

总而言之,我做到了

brew install pyenv
pyenv install 3.8.5
pyenv virtualenv 3.8.5 myproject
pyenv shell myproject 
pip install jupyter notebook matplotlib pandas numpy scipy

然后我从终端启动了 jupyter notebook(我尝试了jupyter notebookjupyter lab)。当我输入import numpy as np 时,我得到了

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-0aa0b027fcb6> in <module>
----> 1 import numpy as np

ModuleNotFoundError: No module named 'numpy'

但在下一个单元格中,如果我评估 !pip install numpy,我会得到

Requirement already satisfied: numpy in /Users/<my_username>/.pyenv/versions/3.8.5/envs/myproject/lib/python3.8/site-packages (1.19.1)

还有,!which python!which pip 返回

/Users/<my_username>/.pyenv/shims/pip
/Users/<my_username>/.pyenv/shims/python

怎么可能在同一个 jupyter notebook 中找不到 numpy 但 pip 说 numpy 已经安装?我似乎永远无法让我的 Python 环境正常运行!

【问题讨论】:

  • 你能把which jupyter的结果加起来吗?
  • 来自同一个笔记本,/Users/&lt;my_username&gt;/.pyenv/shims/jupyter

标签: python pip jupyter


【解决方案1】:

我遇到了完全相同的问题。我认为这完全是由于您的“变化的点子列表”。在创建 shims 路径之前(在安装 pyenv 之前),您可能已经通过 pip install 安装了一堆库。在创建 shims 之后,您可能还安装了一些其他的。所以你的 jupyter-notebook 和 jupyter-lab 可能无法访问之前安装的库。

由于您已经通过homebrew 安装了pyenv,因此无需触及其他任何东西,只需通过homebrew 重新安装jupyterlab 即可。

我用过这个:

brew install jupyterlab

它解决了我的问题。

来源:https://formulae.brew.sh/formula/jupyterlab

【讨论】:

    猜你喜欢
    • 2018-12-14
    • 2021-01-11
    • 1970-01-01
    • 2021-04-06
    • 2020-05-16
    • 1970-01-01
    • 1970-01-01
    • 2019-02-14
    • 1970-01-01
    相关资源
    最近更新 更多