程序中使用pandas进行表格文件处理时,报错了numpy的导入失败问题,错误提示是这样的
Traceback (most recent call last):File "D:/pandastest.py", line 1, in <module>import pandas as pdFile "E:\Python\Python38\lib\site-packages\pandas\__init__.py", line 16, in <module>raise ImportError(
ImportError: Unable to import required dependencies:
numpy: IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.We have compiled some common reasons and troubleshooting tips at:https://numpy.org/devdocs/user/troubleshooting-importerror.htmlPlease note and check the following:* The Python version is: Python3.8 from "E:\Python\Python38\python_d.exe"* The NumPy version is: "1.24.4"and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.Original error was: No module named 'numpy.core._multiarray_umath'Process finished with exit code 1
根据错误提示,可能出现的原因是numpy版本过低,但是更新numpy和重新安装pandas之后还是这个报错。
根据找到的一些经验帖,也尝试了降低numpy的方式,但是也是有问题的。目前看到的一些解决方式是在conda环境下解决。但是当前问题是使用pip安装。
后来在pycharm中发现了一个问题,电脑系统中安装的是py3.8,pycharm导入的也是3.8但是显示是3.6。可能因为之前安装过3.6的版本,这个应该属于一个小bug,但是不是关键问题。
下面重点来了,使用的调试版本的问题(直接使用了本地python环境,之前默认使用了python_d.exe的程序)。之前在pycharm使用的直接运行方式,不是debug模式运行,需要根据python.exe设置解释器。改了这个确实可以了。。。
经验教训:1、还是创建虚拟解释器更加容易定位和解决问题,也更加好用
2、debug和release两个模式的问题,其实和在VS中是一样的,编译方式也是有影响的