[英]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.
我使用这些包的代码不再有效,并且在导入时出错。
I tried to reverse the update to a previous version installation, without success.我试图将更新反转到以前的版本安装,但没有成功。
I checked Python produces: OSError: [WinError 193] %1 is not a valid Win32 application ;我检查了Python 产生: OSError: [WinError 193] %1 is not a valid Win32 application ; but no solution.
但没有解决办法。
I checked https://github.com/pytorch/pytorch/issues/27693 and looked in the PATH on Windows using Environment Variables for User and System;我检查了https://github.com/pytorch/pytorch/issues/27693并使用用户和系统的环境变量查看了 Windows 上的 PATH; but I don't know what to look for.
但我不知道要寻找什么。 oggyoggy448 suggested to remove and reinstall numpy;
oggyoggy448 建议删除并重新安装 numpy; tried it a few times and restarting my PC but no success.
尝试了几次并重新启动我的电脑,但没有成功。
https://python-forum.io/Thread-WinError-193-1-is-not-a-valid-Win32-application suggested running from the command line; https://python-forum.io/Thread-WinError-193-1-is-not-a-valid-Win32-application建议从命令行运行; which you can find below.
您可以在下面找到。
https://superuser.com/questions/1485333/getting-oserror-winerror-193-1-is-not-a-valid-win32-application-while-trying is showing a similar error. https://superuser.com/questions/1485333/getting-oserror-winerror-193-1-is-not-a-valid-win32-application-while-trying显示类似的错误。
I tried uninstalling Anaconda completely and all python versions on my PC;我尝试在我的 PC 上完全卸载 Anaconda 和所有 python 版本; after reinstalling Anaconda and Spyder;
重新安装 Anaconda 和 Spyder 后; the same problem remains.
同样的问题仍然存在。
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.