当前位置: 代码迷 >> python >> 即使 conda 说已安装 Numpy 也无法导入 编辑:
  详细解决方案

即使 conda 说已安装 Numpy 也无法导入 编辑:

热度:97   发布时间:2023-07-16 10:37:34.0

Numpy 不知何故停止工作。 我认为这可能是因为我更改了$PATH变量,但这并没有什么意义。 我确实source .bashr运行了source ,然后source .bashr然后source .bashrc然后source ~/.bashrc ,所以这可能与它有关。

conda list | grep numpy

仍然返回合理的东西

这是我尝试导入 numpy 时打印的错误

>>>import numpy as np

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 23, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'

编辑:

我已经尝试导入我通过 Conda 安装的所有其他软件包,但它们都没有工作。 他们似乎都给出了类似的错误(1. Error in sys.excepthook:和 2. No module named 'apt_pkg'

编辑:

大图:

1) Uninstall conda first
2) Again install conda
3) Then install Anaconda from its official documentation.

复制这些命令:

conda install anaconda-clean
anaconda-clean --yes
rm -rf anaconda3/                 # uninstall

cd /tmp                           # install
curl -O https://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh
sha256sum Anaconda3-5.0.1-Linux-x86_64.sh
# verify legit shell file ^
bash Anaconda3-5.0.1-Linux-x86_64.sh
   # hit 'enter'
yes
source ~/.bashrc
conda install -c anaconda numpy   # install packages
conda install -c anaconda tensorflow

笔记:

我的系统信息:Ubuntu 16.04