Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

python - OSError: [WinError 193] %1 is not a valid Win32 application - when trying to import numpy

I can install numpy or pandas, but I can't import them in cmd, jupyter notebook or sublime text. (However, I can install and import them in Pycharm).

I've already searched different forums/stackoverflow, seeking for an answer, but the most common causes like architecture mismatch (I use Python 32-bit) or spaces in paths seem not to be the issue here. I've tried reinstall Python, but it didn't solve the problem.

The error always points out at "ctypes" lib and it seems to be a problem with numpy module specifically. When I try to import pandas/matplotlib it fails with importing numpy.

>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:UsersjadwiAppDataRoamingPythonPython37site-packages
umpy\__init__.py", line 142, in <module>
    from . import core
  File "C:UsersjadwiAppDataRoamingPythonPython37site-packages
umpycore\__init__.py", line 23, in <module>
    WinDLL(os.path.abspath(filename))
  File "C:UsersjadwiAppDataLocalProgramsPythonPython37-32libctypes\__init__.py", line 356, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application

>>> help('numpy')
problem in numpy - OSError: [WinError 193] %1 is not a valid Win32 application 

>>> import pandas
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:UsersjadwiAppDataLocalProgramsPythonPython37-32libsite-packagespandas\__init__.py", line 13, in <module>
    __import__(dependency)
  File "C:UsersjadwiAppDataRoamingPythonPython37site-packages
umpy\__init__.py", line 142, in <module>
    from . import core
  File "C:UsersjadwiAppDataRoamingPythonPython37site-packages
umpycore\__init__.py", line 23, in <module>
    WinDLL(os.path.abspath(filename))
  File "C:UsersjadwiAppDataLocalProgramsPythonPython37-32libctypes\__init__.py", line 356, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application

I know people had this error before, but, as I mentioned, it seems not to be an architecture mismatch problem, there are no spaces in the paths and I'm really stuck with it. Any suggestions on how to solve it will be very appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Okay, so this eventually helped me:

  1. I uninstalled only a numpy module with "pip uninstall numpy",

  2. I reinstalled it once again with "pip install numpy",

  3. I ran python, imported just one function from numpy (as I thought that maybe just some of the functions can't be imported, not entire numpy) - "from numpy import array"

  4. The function worked,so I tried to import the entire numpy once again and this time it succeeded without OSError.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...