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

Question:

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-packagesnumpy__init__.py", line 142, in <module>
    from . import core
  File "C:UsersjadwiAppDataRoamingPythonPython37site-packagesnumpycore__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-packagesnumpy__init__.py", line 142, in <module>
    from . import core
  File "C:UsersjadwiAppDataRoamingPythonPython37site-packagesnumpycore__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.

Asked By: KamilaW

||

Answers:

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",

Answered By: KamilaW

Reinstalling numpy did not work for me.

I had the same issue and noticed multiple paths pointing to numpy in the error message. E.g.

C:UsersUSERNAMEAppDataRoamingPythonPython37*
C:UsersUSERNAMEAppDataLocalProgramsPythonPython37-32*

I deleted the C:UsersUSERNAMEAppDataRoamingPythonPython37* folder because that was left behind by a previous Python which I had uninstalled. I would not recommend deleting anything until you are certain you won’t break other things, so maybe send it to the recycle bin and restore if it does not fix the issue for you.

Answered By: kym

You can try this, I solved my problem after update package.

pip install --upgrade numpy

if nothing changed, you can upgrade pip first, than upgrade numpy.

python -m pip install --upgrade pip 

(if you want to update all package, please refer to this pageļ¼šHow to upgrade all Python packages with pip?)

Or check the python version is fit your environment or not. Please make sure you remove old version totally after you reinstall new version.

Answered By: Mina chen

I’m using PyCharm, determined to learn the PipEnv virtualization tool(it utilizes SHA256 hashing against downloaded packages), and was experiencing this same exact error message (error 193, %1 not a valid win32 or whatever). I realize this isn’t exactly your scenario however, you’re using python and PyCharm so I figure it might and might help others who arrive here. Anyways…

The way I resolved it was by:
1.) in the ‘Add Python Interpreter’ window (first setting up virtualization interpreter), I had to put "C:UsersericmAppDataRoamingPythonPython38Scriptspipenv.exe" as my "Pipenv executable’.
(After doing this, I began getting a permission error when trying to utilize it)
2.) I had to add my project’s path into the "Working directory" (e.x. C:UsersericmOneDriveDocumentsProgrammingPythonNameOfProject)

No more errors of any kind and my app is fully working again.

Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.