[英]ModuleNotFoundError: No module named 'numpy' - Jupyter Notebook
I'm facing weird issue in my Jupyter-notebook.我的 Jupyter-notebook 遇到了奇怪的问题。
In my first cell:在我的第一个单元格中:
import sys
!{sys.executable} -m pip install numpy
!{sys.executable} -m pip install Pillow
In the second cell:在第二个单元格中:
import numpy as np
from PIL import Image
But it says: ModuleNotFoundError: No module named 'numpy'但它说: ModuleNotFoundError: No module named 'numpy'
I have used this command to install Jupyter notebook:我使用这个命令来安装 Jupyter notebook:
sudo apt install python3-notebook jupyter jupyter-core python-ipykernel
Additional information:附加信息:
pip --version
pip 20.2.2 from /home/maifee/.local/lib/python3.7/site-packages/pip (python 3.7)
python --version
Python 3.7.5
I've had occasional weird install issues with Jupyter Notebooks as well when I'm running a particular virtual environment.当我运行特定的虚拟环境时,我偶尔也会遇到 Jupyter Notebooks 的奇怪安装问题。 Generally, installing with pip directly in the notebook in this form:一般在notebook中直接用pip安装是这样的:
!pip install numpy
fixes it.修复它。 Let me know how it goes.让我知道事情的后续。
Thanks to @suuuehgi.感谢@suuuehgi。 When Jupyter Notebook isn't opened as root:当 Jupyter Notebook 未以 root 身份打开时:
import sys
!{sys.executable} -m pip install --user numpy
I had a similar issue.我有一个类似的问题。 Turns out I renamed an upstream path.结果我重命名了一个上游路径。 And I hadn't deactivated my conda env first.而且我没有先停用我的 conda env。 When I deactivated the env.当我停用 env 时。
conda deactivate
Then when I activated it again, everything was as it should have been.然后当我再次激活它时,一切都应该如此。
conda activate sample
Now I am seeing other issues with jupyter themes... but its not impacting my numpy code.现在我看到 jupyter 主题的其他问题......但它不会影响我的 numpy 代码。 So, at least I fixed the "ModuleNotFoundError: No module named 'numpy'" error所以,至少我修复了“ModuleNotFoundError: No module named 'numpy'”错误
I have the same problem.我也有同样的问题。 My numpy is installed, I am using the same folder as usual.我的 numpy 已安装,我使用与往常相同的文件夹。 If I try 'conda deactivate', I get the message: ValueError: The python kernel does not appear to be a conda environment.如果我尝试“conda deactivate”,我会收到消息:ValueError: The python kernel does not appear to be a conda environment. Please use %pip install
instead.请改用%pip install
。 I added a print of the 'pip install numpy' result and the 'Module not found error' after我在之后添加了“pip install numpy”结果和“找不到模块错误”的打印
Here is a solution which worked for me:这是一个对我有用的解决方案:
lib_path="c:\\users\\user\\python_39\\lib\\site-packages\\"
MODULE_NAME = "module_to_import"
MODULE_PATH = lib_path+MODULE_NAME+"\\__init__.py"
import importlib
import sys
spec = importlib.util.spec_from_file_location(MODULE_NAME, MODULE_PATH)
module = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = module
spec.loader.exec_module(module)
import module_to_import
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.