简体   繁体   English

Python 错误:OSError: [WinError 193] %1 不是有效的 Win32 应用程序

[英]Python error: OSError: [WinError 193] %1 is not a valid Win32 application

After using Anaconda Navigator to update some packages (numpy, matplotlib, ...) and Spyder;使用 Anaconda Navigator 更新一些包(numpy,matplotlib,...)和 Spyder 之后; my code using these packages no longer works and gives error on import.我使用这些包的代码不再有效,并且在导入时出错。

Looking forward to a better understanding and the resolving suggestion...期待更好的理解和解决建议...

While using the IPython console and just typing below:在使用 IPython 控制台并在下面输入时:

In [1]: import numpy

This gives the following output:这给出了以下 output:

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-5-d4cdadb62aa7> in <module>
----> 1 import numpy

~\AppData\Roaming\Python\Python37\site-packages\numpy\__init__.py in <module>
    138
    139     # Allow distributors to run custom init code
--> 140     from . import _distributor_init
    141
    142     from . import core

~\AppData\Roaming\Python\Python37\site-packages\numpy\_distributor_init.py in <module>
     24                 # NOTE: would it change behavior to load ALL
     25                 # DLLs at this path vs. the name restriction?
---> 26                 WinDLL(os.path.abspath(filename))
     27                 DLL_filenames.append(filename)
     28     if len(DLL_filenames) > 1:

E:\Programs\Anaconda\lib\ctypes\__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
    362
    363         if handle is None:
--> 364             self._handle = _dlopen(self._name, mode)
    365         else:
    366             self._handle = handle

OSError: [WinError 193] %1 is not a valid Win32 application

After a couple of nights, the following worked for me (hopefully it may be useful to others having the same problem):几个晚上后,以下对我有用(希望它可能对其他有同样问题的人有用):

In an Ipython environment, typing:在 Ipython 环境中,键入:

In [1]: import numpy

gave the error as shown above.给出了如上所示的错误。 So I did the following:所以我做了以下事情:

In [2]: pip uninstall numpy

getting some lines of code and confirming that numpy is being removed.获取一些代码行并确认 numpy 正在被删除。 After that I tried:之后我尝试了:

In [3]: import numpy

No errors and everything seems to work, (Did not do any install in between.) As if during upgrading some packages before, a double version of numpy was being installed and causing the error log as shown above.没有错误,一切似乎都正常,(中间没有进行任何安装。)好像在之前升级某些软件包期间,正在安装 numpy 的双版本并导致错误日志如上所示。

Exactly the same procedure worked for Matplotlib as well (uninstall and not reinstalling) made it work.完全相同的程序也适用于 Matplotlib(卸载而不是重新安装)使其工作。 Hope this is helpful.希望这会有所帮助。

It happened to me, but unfortunately all the solutions present out there couldn't be of much help.它发生在我身上,但不幸的是,现有的所有解决方案都没有太大帮助。 The possible outcome of this issue is that your python environment is super messed up.此问题的可能结果是您的 python 环境超级混乱。 Although I couldn't resolve this error because possibly I will have to uninstall python from my system, clear caches etc., But to quickly work on the task in hand, I was able to find a workaround尽管我无法解决此错误,因为可能我必须从系统中卸载 python,清除缓存等,但是为了快速完成手头的任务,我能够找到解决方法

The workaround is:解决方法是:

pip install conda

Create a conda environment with your required python version.使用所需的 python 版本创建 conda 环境。 eg:例如:

$ conda create --name conda_virtualenv python=3.6

If you are working in Pycharm or VScode, then manually select this new python interpreter and start working(now you will be able to install the required libraries)如果您正在使用 Pycharm 或 VScode,然后手动 select 这个新的 python 解释器并开始工作(现在您将能够安装所需的库)

If you are working in terminal then activate this environment $ conda activate conda_virtualenv and do whatever you want.如果您在终端中工作,请激活此环境$ conda activate conda_virtualenv并做任何您想做的事情。 If anyone has better workaround, please suggest here.如果有人有更好的解决方法,请在这里提出建议。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 OSError: [WinError 193] %1 不是 Python 中的有效 Win32 应用程序 - OSError: [WinError 193] %1 is not a valid Win32 application in python OSError: [WinError 193] %1 不是有效的 Win32 应用程序 - python - OSError: [WinError 193] %1 is not a valid Win32 application - python OSError: [WinError 193] %1 不是有效的 Win32 应用程序 Python - OSError: [WinError 193] %1 is not a valid Win32 application Python OSError: [WinError 193] %1 is not a valid Win32 application error using GeckoDriver and Firefox through Selenium and Python on Windows - OSError: [WinError 193] %1 is not a valid Win32 application error using GeckoDriver and Firefox through Selenium and Python on Windows Python (Spyder) - 导入 numpy、pandas 等时出错:OSError: [WinError 193] %1 不是有效的 Win32 应用程序 - Python (Spyder) - Error importing numpy, pandas, etc: OSError: [WinError 193] %1 is not a valid Win32 application OSError: [WinError 193] %1 不是有效的 Win32 应用程序 (Pandas) - OSError: [WinError 193] %1 is not a valid Win32 application (Pandas) OSError: [WinError 193] %1 不是有效的 Win32 应用程序 - OSError: [WinError 193] %1 is not a valid Win32 application OSError: [WinError 193] %1 不是有效的 Win32 应用程序 (LibTiff) - OSError: [WinError 193] %1 is not a valid Win32 application (LibTiff) 如何修复“OSError: [WinError 193] %1 不是有效的 Win32 应用程序” - How to fix"OSError: [WinError 193] %1 is not a valid Win32 application" Azure - numpy - OSError:[WinError 193]%1不是有效的Win32应用程序 - Azure - numpy - OSError: [WinError 193] %1 is not a valid Win32 application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM