1

我正在努力与熊猫相处。我正在使用 Thonny 作为 IDLE 学习 Python。我在 cmd 中使用 pip 命令安装了 pandas。不知何故,我无法在 IDLE 中导入 pandas 方法,因此我通过设置将其添加为包。问题是:当我尝试运行以下代码时,我只在 jupyter notebook 和我的 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
4

2 回答 2

5

导入 pandas 和 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 中的旧 Python 文件夹\AppData\Roaming\ 解决了这个问题。似乎 python 引用了一些导致错误的旧文件。

于 2019-10-14T03:40:00.143 回答
1

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

  • pandas从所有操作系统位置卸载。
  • pandas如果问题仍然存在,请重新安装
于 2019-07-26T09:08:44.400 回答