导入Anaconda中的第三方库运行时报错:ImportError: Missing required dependencies ['pandas']

今天碰到一个大坑,花了大半天才搞明白问题出在哪来。事情的经过是这样的:博主下午手贱把已将装好anaconda2给卸载了(同时装了2和3),然后再次安装anconda2后,却发现配置完pycharm的解释器后,代码报错::ImportError: DLL load failed:“xxxx模块没发现”或者ImportError: Missing required dependencies [‘XXX’]。当时就很郁闷,因为整个project已经引入所需的解释器了,即anaconda2集成的许多第三方库,这里面又提示的缺失模块:如pandas等等。但是为什么这里还报缺失模块的错误。如果你碰到的情景跟我类似,不妨往这个方向去考虑解决办法!
下面是保留的报错信息:

D:\Anaconda\envs\py2\python.exe E:/PythonTest/NaiveBayesian.py
Traceback (most recent call last):
  File "E:/PythonTest/NaiveBayesian.py", line 2, in 
    import numpy as np
  File "D:\Anaconda\envs\py2\lib\site-packages\numpy\__init__.py", line 142, in 
    from . import core
  File "D:\Anaconda\envs\py2\lib\site-packages\numpy\core\__init__.py", line 71, in 
    raise ImportError(msg)
ImportError: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the multiarray numpy extension module failed.  Most
likely you are trying to import a failed build of numpy.
Here is how to proceed:
- If you're working with a numpy git repository, try `git clean -xdf`
  (removes all files not under version control) and rebuild numpy.
- If you are simply trying to use the numpy version that you have installed:
  your installation is broken - please reinstall numpy.
- If you have already reinstalled and that did not fix the problem, then:
  1. Check that you are using the Python you expect (you're using D:\Anaconda\envs\py2\python.exe),
     and that you have no directories in your PATH or PYTHONPATH that can
     interfere with the Python and numpy versions 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

     Note: this error has many possible causes, so please don't comment on
     an existing issue about this - open a new one instead.

根据上面的信息,基本就能锁定问题了,后来证实的确是环境变量问题!
这种问题一般是由于环境变量的配置问题导致程序在引用模块的时候发生了错误。所以先检查下你新安装的anaconda(或者其他软件)有没有配置环境变量,像我这种同时使用anaconda2和anaconda3的情况,你还要考虑两种不同版本的环境变量在引用的时候会不会发生冲突。因为毕竟两个版本许多指令都一样。最终我是将两个版本的环境变量都加上后才把问题解决了。

操作过程如下:
添加三个环境变量:
在这里插入图片描述
下面是我之前的anaconda3的环境变量
在这里插入图片描述
还有最后一句话,对环境变量进行修改后记得重启电脑,不然会出现许多意想不到问题哦!

你可能感兴趣的:(工具,Python)