I am trying to test out MongoDB using the speedy and sexy Monary package I've been reading about. I've tried a pip and manual install on my windows 7 64bit machine with the Anaconda 64bit python stack installed and get the following error:
C:\Users\cpye\Desktop\Monary-0.2.3.tar\dist\Monary-0.2.3\Monary-0.2.3>python
Python 2.7.7 |Anaconda 2.0.1 (64-bit)| (default, Jun 11 2014, 10:40:02) [MSC v.1500 64 bit (AMD64)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>> import monary
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "monary\__init__.py", line 4, in <module>
from .monary import Monary
File "monary\monary.py", line 33, in <module>
_load_cmonary_lib()
File "monary\monary.py", line 31, in _load_cmonary_lib
cmonary = CDLL(cmonaryfile)
File "C:\Anaconda\lib\ctypes\__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 193] %1 is not a valid Win32 application
>>>
The setup goes through just fine once I sorted out MinGW and gcc issues. I'm not sure what is getting called that "is not a valid Win32 application" any suggestions?
Thanks!
That error usually means that you are mixing 64-bit and 32-bit executables. Perhaps try using the 32-bit version of Anaconda.
Related
How can I change/upgrade numpy in my Anaconda distribution from 32 bits to 64 bits?
My Windows 10 installation of Anaconda installed a 64 bit version of Python. But it also apparently has installed a 32 bit version of numpy.
(base) C:\Users\i7>python
Python 3.7.4 (default, Aug 9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
resulting in:
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\i7\AppData\Roaming\Python\Python37\site-packages\numpy\__init__.py", line 142, in <module>
from . import core
File "C:\Users\i7\AppData\Roaming\Python\Python37\site-packages\numpy\core\__init__.py", line 23, in <module>
WinDLL(os.path.abspath(filename))
File "C:\Users\i7\Anaconda3\lib\ctypes\__init__.py", line 364, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application
>>>
This is what I currently have
(base) C:\Users\i7>conda list | grep numpy
numpy 1.16.5 py37h19fb1c0_0
numpy-base 1.16.5 py37hc3f5095_0
numpydoc 0.9.1 py_0
I believe that this is the cause of my problem I reported here
Anaconda/Orange3 produces OSError: [WinError 193] %1 is not a valid Win32 application
In case anyone else comes across this, I solved this problem. The issue was with some left-over directories from a previous uninstall of Python 3.7 that didn't get deleted during the process.
File "C:\Users\i7\AppData\Roaming\Python\Python37\site-packages\numpy\__init__.py",
Once I deleted this directory (C:\Users\i7\AppData\Roaming\Python\Python37) it all worked. Credit goes to a comment in How to use anaconda packages for python 3.7 on windows 10? by #FlyingTeller
Im on windows 10 Pro 64 bit version.
I download Anaconda3-2019.03-Windows-x86_64.exe from this page: https://www.anaconda.com/distribution/
I double click the exe and follow the steps - I install it system wide at C:\ProgramData\Anaconda3.
I launch the anaconda prompt. I create a virtualenv with conda create --name pythone37 python=3.7. I do conda install numpy (for instance)
Then I get :
Python 3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
C:\Users\Alex Marshall\AppData\Roaming\Python\Python37\site-packages\numpy\.libs\libopenblas.JKAMQ5EVHIVCPXP2XZJB2RQPIN47S32M.gfortran-win32.dll
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Alex Marshall\AppData\Roaming\Python\Python37\site-packages\numpy\__init__.py", line 142, in <module>
from . import core
File "C:\Users\Alex Marshall\AppData\Roaming\Python\Python37\site-packages\numpy\core\__init__.py", line 24, in <module>
WinDLL(os.path.abspath(filename))
File "C:\Users\Alex Marshall\.conda\envs\python37\lib\ctypes\__init__.py", line 356, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application
It seems to happen with any package that calls external C libraries (I think thats why its using WinDLL?). Also happens with numba for instance.
It does not happen with python3.6 or 32bit python. What gives? Is this just broken on windows for 3.7 64bit?
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 my situation.
Background:
I'm using a venv, it gets activated internally with activate_this.py via:
exec(compile(open(venv_script, "rb").read(), venv_script, 'exec'), dict(__file__=venv_script))
This worked on python2 at least...
when I import numpy I get:
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Dropbox (CEP)\venvs\win\CYAN\Lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import core
File "C:\Dropbox (CEP)\venvs\win\CYAN\Lib\site-packages\numpy\core\__init__.py", line 23, in <module>
WinDLL(os.path.abspath(filename))
File "C:\Python37\lib\ctypes\__init__.py", line 356, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application
If I activate the venv normally, I can import numpy fine, so I'm guessing the problem is how I'm using activate_this.py...
Minimal case:
C:\Dropbox (CEP)\venvs>virtualenv testEnv
Using base prefix 'c:\\users\\brianp\\appdata\\local\\programs\\python\\python37-32'
New python executable in C:\DROPBO~1\venvs\testEnv\Scripts\python.exe
Installing setuptools, pip, wheel...
done.
C:\Dropbox (CEP)\venvs>testEnv\Scripts\activate
(testEnv) C:\Dropbox (CEP)\venvs>pip install numpy
Collecting numpy
Using cached https://files.pythonhosted.org/packages/61/be/b4d697563d4a211596a350414a87612204a8bb987c4c1b34598cd4904f55/numpy-1.16.2-cp37-cp37m-win32.whl
Installing collected packages: numpy
Successfully installed numpy-1.16.2
(testEnv) C:\Dropbox (CEP)\venvs>deactivate
C:\Dropbox (CEP)\venvs>python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> this_file = 'testenv/Scripts/activate_this.py'
>>> exec(open(this_file).read(), {'__file__': this_file})
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Dropbox (CEP)\venvs\testenv\Lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import core
File "C:\Dropbox (CEP)\venvs\testenv\Lib\site-packages\numpy\core\__init__.py", line 23, in <module>
WinDLL(os.path.abspath(filename))
File "C:\Python37\lib\ctypes\__init__.py", line 356, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application
>>> exit()
C:\Dropbox (CEP)\venvs>testEnv\Scripts\activate
(testEnv) C:\Dropbox (CEP)\venvs>python
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 22:20:52) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>>
This is a well known error: it's an architecture mismatch 032bit / 064bit (pc032 / pc064), in your case trying to load a 032bit .dll in a 064bit process. To make things clear, NumPy contains a bunch of .dlls that get loaded in the current process when importing it.
It's actually a duplicate of [SO]: Python Ctypes - loading dll throws OSError: [WinError 193] %1 is not a valid Win32 application (#CristiFati's answer), but I'm going to detail.
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 pc032:
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
In this case, import numpy works (and NumPy (and the .dlls that it contains) is pc032)
The Python interpreter launched from outside testEnv is pc064:
3rd 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), and import numpy picks the pc032 version from testEnv, which obviously fails
To get rid of this error you can either (listing some of the possible options):
Use a pc032 Python from outside VEnv (C:\Dropbox (CEP)\venvs\python)
The other way around: create a testEnv64 VEnv, 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)
Might also want to check [SO]: PyCharm doesn't recognize installed module (#CristiFati's answer).
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)
I have installed python 3.7 on my computer. It seems not possible to import socket in CMD:
C:\Users\Sina\py
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python37-32\lib\socket.py", line 49, in <module>
import _socket
ImportError: Module use of python27.dll conflicts with this version of
Python.
>>>
But surprisingly, I am able to import socket in IDLE (Python 3.7).
I searched but didn't find any 'python27.dll' file in the installation directory
of python 3.7 (C:\Python37-32)
EDIT: There was a _socket.pyd file at "C:\Users\Sina" which used to make the confliction. I deleted it and the problem got fixed. Thanks to Aran-Fey!
I have a Python 2.7.8. 32-bit installed on Windows 10 64 bit. When I try to import numpy I get the following error:
ActivePython 2.7.8.10 (ActiveState Software Inc.) based on
Python 2.7.8 (default, Jul 2 2014, 19:50:44) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Igic\AppData\Roaming\Python\Python27\site-packages\numpy\__init__.py", line 137, in <module>
import add_newdocs
File "C:\Users\Igic\AppData\Roaming\Python\Python27\site-packages\numpy\add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "C:\Users\Igic\AppData\Roaming\Python\Python27\site-packages\numpy\lib\__init__.py", line 4, in <module>
from type_check import *
File "C:\Users\Igic\AppData\Roaming\Python\Python27\site-packages\numpy\lib\type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "C:\Users\Igic\AppData\Roaming\Python\Python27\site-packages\numpy\core\__init__.py", line 5, in <module>
import multiarray
ImportError: DLL load failed: %1 is not a valid Win32 application.
I have installed numpy-1.9.2+unoptimized-cp27-none-win32.whl from this page
From CGohlke's page:
The binaries are compatible with the official CPython distribution on Windows >=6.0. Chances are they don't work with custom Python distributions included with Blender, Maya, ArcGIS, OSGeo4W, ABAQUS, Cygwin, Pythonxy, Canopy, EPD, Anaconda, WinPython etc.
My guess is that the same is also true of ActivePython.
I would recommend either installing the official CPython Windows binary from here, or installing the Anaconda distribution from here, which comes with numpy, scipy, matplotlib and a raft of other scientific Python packages.