I am using windows 7 64 bit machine. I installed Visual studio 2010 and developed a simple win32 dll to add 2 numbers.. The dll is created and i used a test application to test the dll and it works fine..
Now i write python script(shown below) to use this library. But i get the following error message.
Traceback (most recent call last):
File "C:\Users\sbritto\Documents\Visual Studio 2008\Projects\MathFuncsDll\Debug\MathFuncs.py", line 5, in <module>
lib = ctypes.WinDLL('MathFuncsDll.dll',use_last_error=True)
File "C:\Python27\lib\ctypes\__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 193] %1 is not a valid Win32 application
Python Script
import ctypes
from ctypes import *
#lib = cdll.LoadLibrary("MathFuncsDll.dll")
lib = ctypes.WinDLL('MathFuncsDll.dll',use_last_error=True)
print lib
Kindly let me know ASAP.
Thanks in advance
You'll get this error if you try to open a 64-bit DLL using a Python interpreter compiled for a 32-bit machine, or vice versa. So, if this is a 64-bit DLL you need to make sure you are running a 64-bit Python.
Related
I'm trying to setup my first development for esp32 with eclipse on windows 7.
I installed esp-idf using esp-idf-tools-setup.exe installer which should install
everything needed.
I'm testing with the hello world example app from esp-idf. I can compile it using the python command line
idf.py build
But I need eclipse, it's a bit less obvious... I followed these instructions:
In this page, I can see that there's a need of msys. So I installed
msys2 64 bits.
I copied the xtensa-esp32-elf dir into the "msys64\var\opt" directory to match the PATH variable (and updated it based on the documentation)
Now, when compiling with eclipse, I got the following error:
Traceback (most recent call last):
File "C:/program/esp-idf/tools/windows/eclipse_make.py", line 36, in <module>
main()
File "C:/program/esp-idf/tools/windows/eclipse_make.py", line 29, in main
make = subprocess.Popen(["make"] + sys.argv[1:] + ["BATCH_BUILD=1"], stdout=subprocess.PIPE)
File "C:\python27\lib\subprocess.py", line 390, in __init__
errread, errwrite)
File "C:\python27\lib\subprocess.py", line 640, in _execute_child
startupinfo)
WindowsError: [Error 2] Le fichier spécifié est introuvable
Python make is unable to launch "make". The thing is I can't find a make exe anywhere...
This other page states that I must run
make menuconfig
before building with eclipse but, of course, this does not work better for the same reason...
What should I do?
Well, in windows you have nmake (IIRC installed with visual studio tools - or the free where vstools compiler pack). Or you can install something more like gnu-make from one of:
mingw32 : link
cygwin : link
msys2 : link
gnuwin32 : link
There are others as well. Some of these have make command (if you add the bin folder to your path) others will have things like mingw32-make which you may have to alias (I made a batch file called make.bat which just calls mingw32-make %*. But where ever you install make (and nmake IMHO is a really limited poor version of make) you need to add it to your windows path before you run your python script. So in short I think you are just missing a set of tools...
Another option is to just copy ...\MinGW\bin\mingw32-make.exe to ...\MinGW\bin\make.exe
I did add mys2 thinking it will contain everything needed.
In fact msys2 is delivered with a very minimal set of features. I had to install make using the msys2 package manager with the following command:
pacman -S make
Pretty simple when you know!
For esp-idf cmake projects, try this https://github.com/espressif/idf-eclipse-plugin
edit September, 2, 2017, 1pm
I eventually managed to build a .exe with pyinstaller after many episodes.
Unfortunately I failed to deal with the ‘theano’ module (that is required in my case by the ‘pymc3’ module) and I had to modify the .py files and give up part of the application. My description below has two aims: first it may help; second could anyone help me building a .exe for windows 7+, with the ‘theano’ module ?
reminder: My python 3 script opens a simple GUI made with Qt Designer in a ‘.ui’ file and imports pyqtgraph (with pyqt5), pymc3 (and thus theano that is required by pymc3), scipy, numpy, os, sys. It will be distributed on machines with Windows 7+. I tried to build a ‘.exe’ with py2exe, cx_freeze, pynsist and pyinstaller (I opened and updated several posts, this one is still opened: build a .exe for Windows from a python 3 script importing pyqtgraph and opening a GUI) but all failed. My best result (with pyinstaller) is described below after I had to give up theano.
the command line I ended up with is: pyinstaller —noupx —onefile —add-data “toto.ui;.” toto.py. But strangely:
1 the qt designer file ‘toto.ui’ is not included and must be distributed together with the .exe. Otherwise there is an error message when running the .exe saying toto.ui not found;
2 the ‘platforms’ directory from the ‘Library/plugin’ directory of the python environment must also be distributed along with the .exe. Otherwise there is an error message when running the .exe ‘this application has failed to start because it could not find the qt
platform plugin windows’ (but there is no error message from pyinstaller when building !)
3 the .exe is 220MB big ! it seems pyinstaller includes a bunch of useless things during the building.
pyqtgraph problem:
At first sight, the module ‘pyqtgraph’ seems to be incompatible with pyinstaller. Indeed, when the python code imports pyqtgraph, pyinstaller gives a SyntaxError: ‘yield’ inside async function. This seems to me very awkward (is this a bug in pyinstaller ?) because I had the impression from forums this is related to asynchronous generators that are only compatible with python 3.6, while pyinstaller works only with python 3.5- that is not compatible with asynchronous generators… so why does pyinstaller use this ? It turns out this bug-like feature is disabled in a new version of pyinstaller that is not released (and so not installed by default): pip install git+https://github.com/pyinstaller/pyinstaller, thanks to 9dogs (in comments). I also found it may help to explicitly write os.environ[‘PYQTGRAPH_QT_LIB'] = 'PyQt5’ or ‘PyQt4’ before importing pyqtgraph in the py file(s)
theano problem:
theano turns out to make several implicit imports that are not detected by pyinstaller. Thus the building looks ok but when running the .exe you get error messages like ‘no module theano.tensor.shared_randomstreams’. Unfortunately I failed to use the '--hidden-import' option of pyinstaller so I added explicitly the imports in the py file(s) (in this example ’import theano.tensor.shared_randomstreams’ ).
But this is not the end: after that, the file ‘…\AppData\Local\Temp_MEI35682\theano\gpuarray\blockgemv.c' is missing, leading to [4128] Failed to execute script. I don’t know what this file is and didn’t find information. I gave up and removed part of the GUI to avoid theano. Can anyone help me using theano with pyinstaller ?
Windows 10 32 bit
Opencv 3.1.0
Opencv_contrib
Visual Studio 2015
Python 2.7
CMake
I have been trying to install OpenCV 3.1.0 with extra modules from the opencv_contrib github page. Following many tutorials I use the CMake GUI and configure (to visual studio 14 2015) and generate the opencv/build files. I then load up the gnerated opencv.sln file in Visual Studio and build the BUILD_ALL file and then build the INSTALL file. A successful cv2.pyd file is loaded into python for me under Python27/Lib/site-packages which is the same location for the vanilla opencv 2 and 3 builds you can download. My issue is when I try to import cv2 I get the following error:
import cv2
Traceback (most recent call last):
File "", line 1, in
ImportError: DLL load failed: The specified module could not be found.
I have scoured the internet trying to figure out how to fix the issue. I have downloaded software that repairs DLL paths but didn't work.
Any help would be appreciated I have working on solving this problem for over 30 hours now and am going crazy.
This is a photo from my Dependency Checker
Solved: By using the Dependency Checker on the cv2.pyd file I was able to determine that I was missing the connections for some modules and features. They were missing their corresponding .dll file. Going into where I built OpenCV with extra modules I found the necessary .dll files and copy pasted them to the same location where the cv2.py is stored in python.
I am on Windows, and I wish to use Python Bindings for VLC. I've already downloaded the module from https://github.com/oaubert/python-vlc as per the instruction. But, still I can't import the module.
The error looks like this :
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
import vlc
File "c:\python27\python-vlc-1.1.2\vlc.py", line 173, in <module>
dll, plugin_path = find_lib()
File "c:\python27\python-vlc-1.1.2\vlc.py", line 150, in find_lib
dll = ctypes.CDLL('libvlc.dll')
File "C:\Python27\lib\ctypes\__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found
My aim is to stream the openCV webcam video inside a wxPython window using vlc instance.
I solved the problem myself. I was trying to load a 32-bit dll from a 64-bit process, that's why it doesn't worked out. Finally I am able to fix it by using a 64-bit dll.
I tried running lldb on my mac and get this at startup:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/System/Library/PrivateFrameworks/LLDB.framework/Versions/A/Resources/Python/lldb/embedded_interpreter.py", line 1, in <module>
import readline
ImportError: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/readline.so: no appropriate 64-bit architecture (see "man python" for running in 32-bit mode)
Traceback (most recent call last):
File "<string>", line 1, in <module>
NameError: name 'run_one_line' is not defined
Traceback (most recent call last):
File "<string>", line 1, in <module>
NameError: name 'run_one_line' is not defined
Traceback (most recent call last):
File "<string>", line 1, in <module>
NameError: name 'run_one_line' is not defined
I tried adding the environment variable VERSIONER_PYTHON_PREFER_32_BIT=yes but this error still appears. I'd reckon that the lldb is using a different python environment than it's Mac host so where do I make the change to make it use 32bit mode? thanks.
UPDATE:
I did an arch -i386 lldb and it works in 32-bit. To make it work in 64-bit, I installed a 64-bit version of python readline for OS X but got more problems with native python libraries such as termios and time. So I downloaded python 2.7.3 64-bit installer DMG file and installed its binary; now lldb works in 64 bit finally on my 10.8 mountain lion. Thanks.
It looks like you installed /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/readline.so at some point on your system (I don't see it on my Mac OS X 10.7.5 installation, although maybe it's included in 10.8), and that dylib is only built 32-bit. You can confirm with
file /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/readline.so
on your system. You could try to force lldb to also run in 32-bit mode (the distribution binary is built 32-/64- universal) but instead I would recommend removing that 32-bit-only readline.so from your system unless you really need it there.
For the sake of anyone else coming to this question looking for a quick fix - Linus Oleander's answer worked for me -- that is, run
pip install six
Hazarding a guess as to why this works, I think this smooths over some python incompatibility issues that lldb is facing when running on machines with a 'non-standard' python installation. This also works when using Homebrew's version of llvm.