自制软件升级后Jupyter Notebook ModuleError [英] Jupyter Notebook ModuleError after Homebrew Upgrade

查看:94
本文介绍了自制软件升级后Jupyter Notebook ModuleError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Jupyter已有一段时间了,它工作得很好.我通过Homebrew安装了Jupyter和Python.我在MacOS上运行.

I have been using Jupyter for some time now and it has worked just fine. I have Jupyter and Python installed via Homebrew. I am running on MacOS.

昨天,我运行了命令brew upgrade,现在我的Jupyter笔记本无法找到任何已安装的python软件包.我将以Numpy为例.

Yesterday, I ran the command brew upgrade and now my Jupyter notebook is unable to find any of the installed python packages. I will use Numpy as the example.

当我在Jupyter笔记本中时,我会尝试

When inside of a Jupyter notebook, I try to do

import numpy

我收到消息:

ModuleNotFoundError: No module named 'numpy'

但是,如果我在终端窗口中启动python,那么我可以毫无问题地导入Numpy.

If, however, I launch python in a terminal window, then I can import Numpy without issue.

我首先通过重新发出安装命令来检查软件包是否已正确安装

I first checked that the package was installed correctly by re-issuing the install command

brew install numpy

输出:

Warning: numpy 1.18.4 is already installed and up-to-date
To reinstall 1.18.4, run `brew reinstall numpy` 

我也参加了

pip install numpy

并得到:

Requirement already satisfied: numpy in /usr/local/lib/python3.7/site-packages (1.18.4)

现在,这是我感到困惑的地方,因为我希望路径指向/usr/local/Cellar/之类的东西,所以我检查了Jupyter笔记本内部的路径:

Now, this is where I got confused because I expected the path to point to something like /usr/local/Cellar/, so I checked the path inside of the Jupyter notebook:

import sys
sys.path

输出:

['/Users/kseuro/Dropbox/Dev/',
 '/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python38.zip',
 '/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8',
 '/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8/lib-dynload',
 '/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8',
 '',
 '/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8/site-packages',
 '/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8/site-packages/IPython/extensions',
 '/Users/kseuro/.ipython']

好吧,所以Homebrew希望Jupyter使用Python3.8吗?所以我尝试了brew switch python 3.8并得到了:

Ok, so Homebrew wants Jupyter to use Python3.8? So I tried brew switch python 3.8 and got:

Error: python does not have a version "3.8" in the Cellar.
python's installed versions: 3.7.7

我觉得我现在已经不懂事了,需要帮助弄清楚下一步该怎么做.我不想从改变路径开始.

I feel like I'm out of my depth now and need help figuring out what to do next. I don't want to start by just changing paths around.

建议?非常感谢.

推荐答案

我弄清楚该怎么做—为我将来的自己和可能会偶然发现它的其他人发布解决方案.

I figured out what to do — posting the solution for my future self and others who may stumble upon this.

由于Jupyerlab位于其自己的地窖中,因此Python程序包需要最终位于

Since Jupyerlab is in its own Cellar, the Python packages need to end up in the

/usr/local/Cellar/jupyterlab/x.y.z/libexec/lib/python3.x/site-packages

目录,其中x, y, z是整数,以便Jupyter内核可以找到它们.

directory, where x, y, z are integers, so that the Jupyter kernel can find them.

您可以通过以下方式进行此操作:

You can do this by calling:

import sys
!{sys.executable} -m pip install 'package-name'

在Jupyer笔记本中.

inside of the Jupyer notebook.

一切都很好,

这篇关于自制软件升级后Jupyter Notebook ModuleError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆