2

I am trying to get along with pandas. I am learning Python using Thonny as IDLE. I installed pandas using the pip command in my cmd. Somehow i couldnt import pandas method in my IDLE, therefore i added it as package through settings. Problem is: when I try running following code, i only get the error in jupyter notebook and my cmd, but not in the 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
Wumba
  • 99
  • 1
  • 12
  • Are you able to launch this application not from python code but from command line ? – Nikolai Shevchenko Apr 30 '19 at 09:28
  • if I enter this code in command line, I directly get the error...seems like installation of the pandas library via pip install somehow didn't work...not sure what to try nex – Wumba May 03 '19 at 08:40

2 Answers2

6

I was getting the same error message while importing pandas and 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

I installed Anaconda in E:\Anacond\ but still it was referencing to C:\Users\Dell\AppData\Roaming\Python\Python37\site-packages\numpy__init__.py I deleted the old Python Folder inside C:\Users\Dell\AppData\Roaming\ which resolved the issue.It seems like python was referencing to some old files which caused the error.

shiva baral
  • 69
  • 1
  • 6
1

Another thing might have happened. VS code automatically searches for the numpy and other packages from predefined OS locations. You might be using the 32 bit version of numpy instead of a 64 bit version. To fix this, you can

  • Uninstall pandas from all OS locations.
  • Reinstall pandas if the problem persists
B--rian
  • 5,578
  • 10
  • 38
  • 89
  • Welcome to SO! Please make sure that you are not copy-pasting the same answer to multiple (old) questions, but rather mark the questions as duplicate (if they are). – B--rian Jul 26 '19 at 09:29