Python Produces: Oserror: [winerror 193] %1 Is Not A Valid Win32 Application, But Only With Activate_this.py
Solution 1:
This is a well known error: it's an architecture mismatch (32bit / 64bit), in your case trying to load a 32bit.dll in a 64bit process. To make things clear, numpy contains a bunch of .dlls that get loaded in the current process when importing it.
The examples in the question are twisted and hard to read: some example that works, then some that doesn't then some that works again and so on (for example I don't even know what's the 2 snippet purpose), instead of clearly separating scenarios that do work from those that don't.
Anyway in spite of the above, I was able to identify the problem.
The testEnv environment that you created (and installed numpy in) is 32bit:
3 snippet (begin):
Using base prefix 'c:\users\brianp\appdata\local\programs\python\python37-32'
3 snippet (end):
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 22:20:52) [MSC v.1916 32 bit (Intel)] on win32
- In this case,
import numpy
works (and numpy (and the .dlls that it contains) is 32bit)
The Python interpreter launched from outsidetestEnv is 64bit
- 3 snippet (mid):
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
- When running testEnv's activate_this.py in the current process, it adds testEnv paths to %PYTHONPATH% (
sys.path
), andimport numpy
picks the 32bit version from testEnv, which obviously fails
- 3 snippet (mid):
To get rid of this error you can either (listing some of the possible options):
- Use a 32bitPython from outside VEnv (
C:\Dropbox (CEP)\venvs>python
) - The other way around: create a testEnv64VEnv, and use its activate_this.py
- Don't use activate_this.py at all, unless you know what you're doing (I'd recommend this one)
Solution 2:
Another thing might have happened. VS code
automatically searches for the numpy and other packages from predefined OS locations. It might have found out 32 bit
version of numpy
instead of a 64 bit
version.
Fix:
Uninstall numpy
from all OS locations
* In VS code terminal
. Type pip uninstall numpy
or conda uninstall numpy
(If you use Anaconda
)
* Restart VS code
* Voila! (Reinstall numpy if the problem persists)
Post a Comment for "Python Produces: Oserror: [winerror 193] %1 Is Not A Valid Win32 Application, But Only With Activate_this.py"