This is presumably the same as Python produces: OSError: [WinError 193] %1 is not a valid Win32 application However, that has no answers, and I have additional details for m
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)
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 2nd 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:
3rd snippet (begin):
Using base prefix 'c:\users\brianp\appdata\local\programs\python\python37-32'
3rd 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
import numpy
works (and numpy (and the .dlls that it contains) is 32bit)The Python interpreter launched from outside testEnv is 64bit
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
sys.path
), and import numpy
picks the 32bit version from testEnv, which obviously failsTo get rid of this error you can either (listing some of the possible options):
C:\Dropbox (CEP)\venvs>python
)