numpy: cannot import name '_distributor_init'

  这个问题网上的解决方式并不多,而且我并没有找到有效的处理方式。
  然,其实在报错的时候,它已经给出了解决方式,已经给出了!!!一定要记得仔细看,我当时是服务器上的flask项目,报错信息在 apache的error.log 中,上面给了很详细的解释和解决方式,只是我只看了最后一行……尴尬。

 Try uninstalling and reinstalling numpy.
…… - If you have already done that, then:
……   1. Check that you expected to use Python3.4 from "/var/www/flask_demo/venv/bin/python3",
…… and that you have no directories in your PATH or PYTHONPATH that can
…… interfere with the Python and numpy version "1.17.2" you're trying to use.
…… 2. If (1) looks fine, you can open a new issue at
…… https://github.com/numpy/numpy/issues.  Please include details on:
…… - how you installed Python
…… - how you installed numpy
…… - your operating system
…… - whether or not you have multiple versions of Python installed
…… - if you built from source, your compiler versions and ideally a build log
…… - If you're working with a numpy git repository, try `git clean -xdf`
…… (removes all files not under version control) and rebuild numpy.

  赶巧,我这边问题正好是第一个,项目用的依赖包是 Python3.7.4 版本的,结果运行的python却是 3.4 的,所以就报错了。卸了Python 3.4 ,重装 Python 3.7 就解决了。当然也可以改用 Python 3.4版本适配的numpy,应该也能解决问题。不过我这边其他依赖包也都是用的 Python3.7 的,所以就直接重装Python了。

参考文章:【1】python - ImportError: cannot import name _distributor_init - Stack Overflow
     【2】python - ImportError: cannot import name NUMPY_MKL - Stack Overflow
     【3】python - Numpy - ImportError: cannot import name _distributor_init - Stack Overflow
     【4】 Python导入Scipy子模块时出现问题? - 知乎

发布了195 篇原创文章 · 获赞 139 · 访问量 12万+

猜你喜欢

转载自blog.csdn.net/qq_39564555/article/details/102586930