Is there now an easy protocol to build a .exe from python 3.5+, using modules pyqtgraph, qt5, theano, pymc3, numpy, scipy, os and sys, and opening a simple GUI stored in a '.ui' file ? I lost hours and eventually failed to make one (for w7-64 bits). Help !
preliminary failure with py2exe: I first install py2exe for python 3 but it turns out this is not compatible with my python 3.6 yet, so I downgraded to python 3.5… to get a bunch of errors. Then I went to forums and tried the proposed cures but failed (I’m uneasy with windows), the alternative being to downgrade to python 3.4… So I downgraded to python 3.4 to get an error concerning a missing ‘msvcr100.dll’ that I tried to install following instructions on forums but by default I don’t have the permission to modify system directories… When I eventually had this permission it turns out the ‘regsvr32’ command fails (isn’t this for 32 bits ? but there is no ‘regsvr64’…). Following episodes are described below.
update august 23, 2017, 1pm:
I also tried pyinstaller as advised but it failed (see my related question build a .exe for Windows from a python 3 script importing theano with pyinstaller)
I also tried cx_freeze but it failed (see my related question build a .exe for Windows from a python 3 script)
I also tried pynsist but it fails (same link than above)
what's next ?
update september, 2, 2pm:
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. Could anyone help me building a .exe for windows 7+, with the ‘theano’ module ?
see build a .exe for Windows from a python 3 script importing theano with pyinstaller
Pyinstaller Works with Python 3.5 and it is working even for packages like tensor-flow, scipy , etc (The packages I worked with)
py -3.5 pip install pyinstaller
then go the C:\Users\user\AppData\Local\Programs\Python\Python35\Scripts
and run the command
pyinstaller <code .py file along with directory> --onefile
--onefile : is for compressing the build and get a single file as output
I would suggest pyinstaller see http://www.pyinstaller.org/
The pyinstaller already supports 3.5
The development version supports 3.6
It is better to use spec file to import other hidden libraries. I listed all Sklearn libraries and add them to spec file as a hiddenimports, you can add libraries you used in your project.
I have a situation very much like the one at Error "ImportError: DLL load failed: %1 is not a valid Win32 application", but the answer there isn't working for me.
My Python code says:
import cv2
But that line throws the error shown in the title of this question.
I have OpenCV installed in C:\lib\opencv on this 64-bit machine. I'm using 64-bit Python.
My PYTHONPATH variable: PYTHONPATH=C:\lib\opencv\build\python\2.7. This folder contains cv2.pyd and that's all.
My PATH variable: Path=%OPENCV_DIR%\bin;... This folder contains 39 DLL files such as opencv_core246d.dll.
OPENCV_DIR has this value: OPENCV_DIR=C:\lib\opencv\build\x64\vc11.
The solution at Error "ImportError: DLL load failed: %1 is not a valid Win32 application" says to add "the new opencv binaries path (C:\opencv\build\bin\Release) to the Windows PATH environment variable". But as shown above, I already have the OpenCV binaries folder (C:\lib\opencv\build\x64\vc11\bin) in my PATH. And my OpenCV installation doesn't have any Release folders (except for an empty one under build/java).
What's going wrong? Can I tell Python to verbosely trace the loading process? Exactly what DLL files is it looking for?
I noticed that, according to http://www.dependencywalker.com/, the cv2.pyd in C:\lib\opencv\build\python\2.7 is 32-bit, whereas the machine and the Python I'm running are 64-bit. Could that be the problem? And if so, where can I find a 64-bit version of cv2.pyd?
Unofficial Windows Binaries for Python Extension Packages
You can find any Python libraries from here.
Please check if the Python version you are using is also 64 bit. If not then that could be the issue. You would be using a 32-bit Python version and would have installed a 64 bit binaries for the OpenCV library.
Wow, I found yet another case for this problem. None of the above worked. Eventually I used python's ability to introspect what was being loaded. For Python 2.7, this means:
import imp
imp.find_module("cv2")
This turned up a completely unexpected "cv2.pyd" file in an Anaconda DLL directory that wasn't touched by multiple uninstall/install attempts. Python was looking there first and not finding my good installation. I deleted that cv2.pyd file and tried imp.find_module("cv2") again and python immediately found the right file and cv2 started working.
So if none of the other solutions work for you, make sure you use Python introspection to see what file Python is trying to load.
In my case, I have 64-bit Python, and it was lxml that was the wrong version--I should have been using the x64 version of that as well. I solved this by downloading the 64-bit version of lxml here:
https://pypi.python.org/pypi/lxml/3.4.1
lxml-3.4.1.win-amd64-py2.7.exe
This was the simplest answer to a frustrating issue.
I just had this problem. It turns out it was just because I was using an 64-bit version of the OpenCV file. I tried the x86 and it worked.
I had the same problem. Here's what I did:
I downloaded the pywin32 wheel file from here, then
I uninstalled the pywin32 module. To uninstall, execute the following command in a command prompt.
pip uninstall pywin32
Then, I reinstalled pywin32. To install it, open the command prompt in the same directory where the pywin32 wheel file lies. Then execute the following command.
pip install <Name of the wheel file with extension>
Wheel file will be like: piwin32-XXX-cpXX-none-win32.whl
It solves the problem for me.
I copied cv2.pyd file from /opencv/build/python/2.7/x86 folder instead of from /x64 folder to C:/Python27/Lib/site-packeges. I followed rest of the instructions provided here.
Added by someone else, not verified: I also copy file cv2.pyd to folder C:/Python27/Lib/site-packages/cv2. It works.
For me the problem was that I was using different versions of Python in the same Eclipse project. My setup was not consistent with the Project Properties and the Run Configuration Python versions.
In menu Project → Properties → PyDev, I had the Interpreter set to Python 2.7.11.
In Run Configurations → Interpreter, I was using the Default Interpreter. Changing it to Python 2.7.11 fixed the problem.
If your build system (CMake in my case) copies the file from <name>.dll to <name>.pyd, you will get this error if the original file wasn't actually a DLL file. In my case, building shared libraries got switched off, so the underlying file was actually a *.lib.
I discovered this error by loading the pyd file in Dependency Walker and finding that it wasn't valid.
Update NumPy.
pip install numpy --upgrade
It works for me!
This one worked for me:
pip install -- pywin32==227
I faced the same issue when I uninstalled and reinstalled a different version of 2.7.x of Python on my system using a 32-bit Windows Installer. I got the same error on most of my import statements.
I uninstalled the newly installed Python, downloaded a 64-bit Windows installer, reinstalled Python again, and it worked.
So I had problems installing vtk under Windows (as I use Python 3.7, there isn't any binary available so far. Just for older Python versions pip install vtk is not working)
I did wrote Python in my cmd:
Python 3.7.3 on win32
So I now know I have Python 3.7.3 running on a 32 bit.
I then downloaded the correct wheel at VTK‑8.2.0‑cp37‑cp37m‑win32.whl
Next I installed that wheel:
pip install VTK-8.2.0-cp37-cp37m-win32.whl
Then I tested it and it worked:
python
import vtk
I experienced the same problem while trying to write code concerning speech-to-text.
The solution was very simple. Uninstall the previous pywin32 using the pip method:
pip uninstall pywin32
The above will remove the existing one which is by default for 32 bit computers. And install it again using
pip install pywin32
This will install the one for the 64 bit computer which you are using.
I had a similar issue while trying to run uvicorn,
Creating a new virtual environment and reinstalling the python packages worked
You can install opencv from official or unofficial sites.
Refer to this question and this issue if you are using Anaconda.
It has a very simple solution.
After installing opencv
place
cv2.pyd from C:\opencv\build\python\2.7\ **x64** to C:\Python27\Lib\site-packages
instead of, place cv2.pyd from C:\opencv\build\python\2.7\ **x86** to C:\Python27\Lib\site-packages
I got this error when trying to import MySQLdb.
What worked for me was to uninstall Python and then reinstall it.
I got the error after installing npm (https://www.npmjs.com/get-npm). One thing it did was install Python even though I already had it.
First I copied cv2.pyd from /opencv/build/python/2.7/x86 to C:/Python27/Lib/site-packeges. The error was
"RuntimeError: module compiled against API version 9 but this version of numpy is 7"
Then I installed numpy-1.8.0-win32-superpack-python2.7.exe and OpenCV works fine.
>>> import cv2
>>> print cv2.__version__
2.4.13
Please make sure that you have installed a Python 2.7.12 or below version. Otherwise you will definitely get this error.
Make sure the Oracle client is 64 bit installed if the OS is 64 bit.
Make sure the Microsoft Visual C++ compiler for Python 2.7 is 64 for bit for a 64 bit OS or 32 bit for 32 bit.
Note: If your OS is 64 bit, install all packages of 64 bit or if the OS is 32 bit, install the 32-bit package.
This has worked for me. I have tried different methods, but this was my best solution.
Open a command prompt and type the following;
pip install opencv-python
(Make sure your Internet connection is on.)
After that, try importing it again.
It could also be that your Anaconda version is 32 bit when it should be 64 bit.
If you are using pycharm I go to settings -> python interpretation and click the + button and search for the name on the list of python packages there
An image showing where to go when you want to install something
I found the solution. Maybe you can try to use the cmd window rather than the Anaconda prompt window to start your first Scrapy test.
I've tried unsuccessfully to get scip running with python. I'm using Yosemite (10.10.3), python 2.7 and have installed scip optimization suit (http://scip.zib.de/download.php?fname=scipoptsuite-3.1.1.tgz) with make.
I can start scip after the installation via the terminal.
sages-MBP:~ sage$ scip SCIP version 3.1.1 [precision: 8 byte] [memory: block] >[mode:optimized][LP solver: SoPlex 2.0.1] [GitHash: bade511]
But when I try to use import scip in python there appears the message
No module named scip
The same error message appears for from zibopt import scip
If I print the system path with print sys.path in python, the folder scipoptsuite-3.1.1/scip-3.1.1/bin is included where the file
scip-3.1.1.darwin.x86_64.gnu.opt.spx is situated.
Is it possible that the reason for the error message is that I haven't linked correctly necessary libraries?
Or which folders have to be included in the pythonpath to get scip working?
I Hope someone can help me out!
You need to install the python interface that comes with SCIP. Go to scip/interfaces/python/ and read the instructions in README and INSTALL. This interface is using Cython to communicate with the C-Code of SCIP.
make will only install the native Linux or Mac binaries/libraries.
The environment variable DYLD_LIBRARY_PATH needs to be set to contain the lib/ directory of the SCIPoptSuite installation (see comment by #саша)
I have an algorithm written in C++ that I want to use in ArcGIS. Arc supports python scripting, so I figured I'd write a python wrapper. I built python on my development PC and then built a module (called "delaunay", to calculate Delaunay triangulations) to wrap the algorithm. On that PC I was using cygwin with mingw g++ and put the .dll that I built into /usr/local/lib/python2.6/site-packages. Works fine.
So now I'm trying to get it to work on the PC that I run GIS on. ArcGIS installs python as part of its own installation, so I put the .dll in /Python26/ArcGIS10.0/Lib/site-packages (which is in the sys.path) and tried to import it. I got the following error:
ImportError: No module named delaunay
Renamed delaunay.dll to delaunay.pyd and got this error:
ImportError: DLL load failed: The specified module could not be found.
I have a feeling it'd work if I put the source on the GIS machine and built and installed it with distutils, but I don't really want to install cygwin or Visual Studio on that machine.
Anyway, I have no idea why I get different messages, what the significance of the messages is, or whether this will work at all (i.e. is the ArcGIS distro of Python incompatible with mine 'cause we used different compilers?)
Also, the dev machine has a Jun 12, 2010 revision of Python 2.6.5 and the GIS machine has a Mar 19, 2010 revision. Maybe that is significant?
Help?
Run python -vvv and you'll see import debug info.
You are probably mixing 32-bit and 64-bit binaries. Binaries from different Python builds are incompatible.
Renamed delaunay.dll to delaunay.pyd and got this error:
ImportError: DLL load failed: The specified module could not be found.
This sounds like delaunay.pyd depends on some other dll that is not found.
I cannot seem to get py2exe to work properly. I have run "python setup.py py2exe" in cmd, as well as "python setup.py install"... and When I try to run my executable setup, I get this same error over and over:
After a week I'm starting to get quite frustrated and I'm hoping to be able to resolve the issue today.
I'm using Python 2.7 and py2exe v0.6.9. 64-bit Windows7
FINALLY, I can die a happy man. After agonizing over this problem for over a week, I figured out that the issue is that I had to download the 64bit version of py2exe from SourceForge. The "Get Latest Version" link that they have at the top is for Python 2.5, which is very misleading because I would have assumed it would at least use the latest version of PYTHON that it supports, which I believe is the version I have, Python 2.7.1.
I had to go into the "Browse All Files" section and manually navigate to v0.6.9 and then pick the appropriate version.
I am now able to create an executable from running "C:\Python27\setup.py py2exe".
thanks all for your help/replies.
The most important lines in that error are the last two -
import py2exe_util
ImportError: DLL load failed: The specified module could not be found.
That means py2exe was not installed completely in the first place. Try re-installing it.
You need a version of py2exe that matches the architecture of your python install.
If you have a 32bit python install you need a win32 py2exe installer.
If you have a x64 python install you need a win64 py2exe installer.
In my case I am on a 64bit machine with a 32bit python install. The Source Forge 'latest' link gave the win64 version of py2exe (because it detected my machine type). But it didn't work, I kept getting the following error:
ImportError: DLL load failed with error code 193
I needed to go back to Source Forge and 'Browse all files' to find the win32 version.
I'm not sure my problem is the same as OPs, but since I found this thread while searching for a solution to my problem, I'll add what I found.
My issue was building 32 bit program on a 64 bit machine. The exe worked fine on other 64 bit machines, but raised the DLL load failed: The specified module could not be found error on other 32 bit machines.
What I ended up figuring out was that py2exe was including windows DLLs that it shouldn't have been in the package. When these DLLs were removed, the error went away.
py2exe has an option to explicitly exclude dlls. Here's a snippet of what worked for me:
setup(
...
options={
'bdist_esky': {
'freezer_module': 'py2exe',
'freezer_options': {
'dll_excludes': [
'CRYPT32.dll',
'IPHLPAPI.DLL',
'MPR.dll',
'MSWSOCK.dll',
'PSAPI.DLL',
'WTSAPI32.dll',
],
},
...
)