-1

I have the same error when trying to import any external library in Python :

import sklearn

runfile('C:/Users/pc/.spyder-py3/temp.py', wdir='C:/Users/pc/.spyder-py3')
Traceback (most recent call last):

  File ~\.spyder-py3\temp.py:1 in <module>
    import sklearn

  File ~\AppData\Roaming\Python\Python39\site-packages\sklearn\__init__.py:80 in <module>
    from . import _distributor_init  # noqa: F401

  File ~\AppData\Roaming\Python\Python39\site-packages\sklearn\_distributor_init.py:22 in <module>
    WinDLL(op.abspath(vcomp140_dll_filename))

  File ~\anaconda3\lib\ctypes\__init__.py:382 in __init__
    self._handle = _dlopen(self._name, mode)

OSError: [WinError 193] %1 n’est pas une application Win32 valide

I tried uninstalling and reinstalling the libraries first, then did the same for Python. It didn't work.

Yan Djin
  • 11
  • 3
  • 1
    You are using a 32-bit binary from 64-bit code, or a 64-bit binary from 32-bit code, or some other architecture mismatch between the callee and library code. – IInspectable Oct 31 '22 at 11:18
  • @IInspectable What can I do about it to solve the problem? – Yan Djin Oct 31 '22 at 12:48
  • 1
    *"What can I do about it to solve the problem?"* - Match the bitness of all binaries that get loaded into your process. @GinoMempin Running 32-bit binaries on 64-bit versions of Windows is fully supported through the WoW64 emulator. – IInspectable Oct 31 '22 at 13:29
  • How do you run your script? What's its content? – CristiFati Nov 04 '22 at 11:02

1 Answers1

0

The error is architecture mismatch and is detailed in [SO]: Python Ctypes - loading dll throws OSError: [WinError 193] %1 is not a valid Win32 application (@CristiFati's answer).
So, technically this is a duplicate, but I'm going to dive a bit deeper.

The root cause of the error is [SO]: PyCharm doesn't recognize installed module (@CristiFati's answer) (also check referenced URLs), point #1. (and possibly #2.).

There are 2 kinds of paths in the traceback:

  1. ~\AppData\Roaming\Python\Python39 - Regular Python (3.9) installation (possibly from Windows Store) - 032bit (pc032). This is the launched interpreter

  2. ~\anaconda3 - Anaconda installation pc064 (based on the error). This is where the package is loaded from

So you're launching a Python instance, and try to load modules from another instance. This is unsupported (and it would still be even if everything would work fine).

Now, since the question is not an MCVE ([SO]: How to create a Minimal, Reproducible Example (reprex (mcve))), as it doesn't mention how the code is run (also it would be good to know what environment variables PATH or PYTHONPATH values are), one can only guess why this situation was reached.

Anyway, to fix this situation (generally), only use one Python instance.
Specific to this situation, make sure to launch Anaconda's Python ([Anaconda.Docs]: Getting started with Anaconda).

CristiFati
  • 38,250
  • 9
  • 50
  • 87