如何修复“ OSError:[WinError 193]%1不是有效的Win32应用程序”

时间:2019-04-30 09:17:55

标签: python-3.x pandas cmd jupyter-notebook thonny

我正试图与熊猫相处。 我正在学习使用Thonny作为IDLE的Python。我在cmd中使用pip命令安装了熊猫。我以某种方式无法在我的IDLE中导入pandas方法,因此我通过设置将其作为软件包添加。 问题是:当我尝试运行以下代码时,我只会在jupyter笔记本和cmd中得到错误,而在thonny IDLE中则不会。

import pandas as pd
df = pd.read_csv("pokemon_data.csv")
print(df)

Out(Cmd):
Traceback (most recent call last):
  File "pokemonData.py", line 1, in <module>
    import pandas as pd
  File "C:\Users\pc\AppData\Roaming\Python\Python37\site-packages\pandas\__init_
_.py", line 13, in <module>
    __import__(dependency)
  File "C:\Users\pc\AppData\Roaming\Python\Python37\site-packages\numpy\__init__
.py", line 142, in <module>
    from . import core
  File "C:\Users\pc\AppData\Roaming\Python\Python37\site-packages\numpy\core\__i
nit__.py", line 23, in <module>
    WinDLL(os.path.abspath(filename))
  File "C:\Users\pc\AppData\Local\Programs\Python\Python37\lib\ctypes\__init__.p
y", line 356, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 ist keine zulässige Win32-Anwendung

Out(jupyter notebook):
OSError                                   Traceback (most recent call last)
<ipython-input-1-686db4b56d1d> in <module>
      1 
----> 2 import pandas as pd
      3 
      4 df = pd.read_csv("pokemon_data.csv")
      5 

~\AppData\Roaming\Python\Python37\site-packages\pandas\__init__.py in <module>
     11 for dependency in hard_dependencies:
     12     try:
---> 13         __import__(dependency)
     14     except ImportError as e:
     15         missing_dependencies.append(dependency)

~\AppData\Roaming\Python\Python37\site-packages\numpy\__init__.py in <module>
    140     from . import _distributor_init
    141 
--> 142     from . import core
    143     from .core import *
    144     from . import compat

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

c:\users\pc\appdata\local\programs\python\python37\lib\ctypes\__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
    354 
    355         if handle is None:
--> 356             self._handle = _dlopen(self._name, mode)
    357         else:
    358             self._handle = handle

OSError: [WinError 193] %1 ist keine zulässige Win32-Anwendung

2 个答案:

答案 0 :(得分:1)

导入熊猫和numpy时出现相同的错误消息。

File "<ipython-input-2-844cb1137ef2>", line 1, in <module>
import  pandas as pd

File "E:\Anacond\lib\site-packages\pandas\__init__.py", line 13, in <module>
__import__(dependency)

File "***C:\Users\Dell\AppData\Roaming\Python\Python37\site- 
packages\numpy\__init__.py***", line 140, in <module>
from . import _distributor_init

File "***C:\Users\Dell\AppData\Roaming\Python\Python37\site- 
packages\numpy\_distributor_init.py***", line 26, in <module>
WinDLL(os.path.abspath(filename))

File "E:\Anacond\lib\ctypes\__init__.py", line 356, in __init__
self._handle = _dlopen(self._name, mode)

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

我在E:\ Anacond \中安装了Anaconda,但仍然引用 C:\ Users \ Dell \ AppData \ Roaming \ Python \ Python37 \ site-packages \ numpy__init __。py 我删除了C:\ Users \ Dell \ AppData \ Roaming \中的旧Python文件夹 解决了问题。似乎python在引用一些旧文件 导致错误的原因。

答案 1 :(得分:0)

可能发生了另一件事。 VS代码自动从预定义的OS位置搜索numpy和其他软件包。您可能使用的是numpy的32位版本,而不是64位版本。要解决此问题,您可以

  • 从所有操作系统位置卸载pandas
  • 如果问题仍然存在,请重新安装pandas