导入pandas触发OSError:[WinError 193] %1不是有效的Win32应用解决方案
问题根因
导入import pandas as pd触发[WinError 193] %1 is not a valid Win32 application报错,是pandas加载依赖numpy时,调用WinDLL加载的DLL文件与当前运行环境架构不匹配、或是numpy安装文件损坏/多版本冲突导致。
可行解决方案
- 确认Python运行环境架构一致性
执行命令查看当前Python架构:python -c "import platform;print(platform.architecture())"
确保后续安装的numpy、pandas包架构与Python架构完全一致,禁止64位Python安装32位版本的科学计算包。 - 卸载重装numpy、pandas包
先执行卸载命令清除现有损坏的安装包:pip uninstall -y numpy pandas
若使用Anaconda环境,优先使用conda命令安装:conda install numpy pandas
若使用原生Python环境,使用pip官方源安装:pip install numpy pandas - 清理多版本numpy冲突
从报错堆栈可发现numpy安装路径为用户全局目录~\AppData\Roaming\Python\Python38\site-packages\numpy\,与Anaconda运行环境路径不匹配,属于多版本numpy冲突。手动进入上述用户全局site-packages目录,删除所有numpy开头的文件夹,再回到当前使用的运行环境重新安装numpy即可。 - 修复Anaconda环境兼容性
若使用Anaconda环境,可执行全量包更新命令修复版本兼容问题:conda update --all
内容的提问来源于stack exchange,提问作者Utkarsh Chalsey
相关产品推荐
相关产品推荐

