I just created an exe with cx_Freeze and proudly handed it over to a co-worker.....and it promptly crashed ("The application was unable to start correctly") I was curious to know if he must have python already installed and ready to go when he runs my exe or if it is something else that I should be worried about. (If that is the case, I will do some more research)
I am using Python 2.7 64 bit, Wxpython, and Cx_Freeze 4.2.7
UPDATE:
So I have found that a download of Python 2.7 DOES indeed fix the problem--but this is not what I really want. I have heard that with the correct options selected in the setup.py script that I can truly create a stand alone--Does ANYONE know about how I could do this? Filesize is no object.
The purpose of cx_Freeze is so that the user doesn't need Python installed. But sometimes there might be some DLL dependencies that aren't sorted out automatically by cx_Freeze. For one example, see my recent question and answer for "ImportError: DLL load failed when importing win32clipboard in application frozen with cx_Freeze".
But if you're getting the message "The application was unable to start correctly", then that sounds as though the problem is some implicit-linking DLL dependency. Try using Dependency Walker to track down which DLL is missing. Let us know your results.
No, he doesn't need to have Python installed - cx_Freeze should copy a Python DLL into the build folder. Make sure that all the files in the build folder are still with the EXE when you run it.
However, it might be necessary for him to install the Microsoft 'Visual C++ redistributable' that Python requires. I don't think cx_Freeze can automatically include that, for legal reasons (but I am not a lawyer, and I'm happy to be proved wrong). The details are in the documentation:
http://cx_freeze.readthedocs.org/en/latest/overview.html#microsoft-visual-c-2008-redistributable-package
Or there may be some other problem with the bundling for your application. I don't know what would cause that error message.
Related
I am trying to create a standalone exe from python code using nuitka. Its a rather sizable program with several libraries including for instance PyQt5.
I have created the exe using:python -m nuitka --standalone --follow-imports --enable-plugin=qt-plugins --enable-plugin=numpy --python-flag=no_site --mingw64 rs_main.py
I have also tried without the --mingw64 and --python-flag=no_site flags but they all give me the same error when I try to execute the resulting exe:
ImportError: LoadLibraryEx 'D:\... ...\rs_main.dist\PyQt5\QtWidgets.pyd' failed: The specified procedure could not be found.
I checked and the file does exist in the correct location.
The compiling itself gives me some warnings but no errors.
Online I found my problem here: https://github.com/Nuitka/Nuitka/issues/73 but to be honest I do not fully understand their journey towards the solution and as I think I understand it should be solved in my version of nuitka which is 0.6.6. On top of that I am running python 3.7.3 on a windows 10 machine.
Hopefully someone can explain me the solution in the referenced link or offer one of their own. thanks in advance.
So this is not really an answer to my question, but if anyone comes across this question, maybe my solution is good enough for them as well.
So although I know it does not do the same as Nuitka I was finally able to create a standalone exe using pyinstaller including some flags such as --hidden-imports and add the path to Qt but I found the feedback of pyinstaller to be rather understandable.
So maybe if you have the same problem as me, this might be a different approach for you as well.
I am doing this practice project to implement a LISP interpreter in Python, using help from here. I wanted to create an exe file for the project, executing which would start a REPL.
I tried using py2exe and pyInstaller but an error is thrown when I execute the output binary, saying that this script cannot run.
Where did I go wrong with my approach and what alternative ways can I use?
Thank you.
It is hard to know for sure but have you checked that all of the required dependencies for your project are either in the same folder as the created executable or (at least) in your path?
The other alternative that I am aware of (and use) is cx_Freeze. This particular exe builder has cross platform support.
cx_Freeze will attempt to automatically find all dependent python modules and include them in the final build. I imagine that the other two options work in the same manner. Packages that cannot be automatically located and binary dependencies (eg dlls, sos) must be explicitly specified in the build configuration scripts.
One method I have for debugging for missing dependencies is to manually copy the suspected missing dependency into the same folder as the .exe to see if it fixes the issue. If it does then I will specify it in the build configuration script.
See https://cx-freeze.readthedocs.io/en/latest/distutils.html for cx_Freeze documentation, in particular section titled build_exe.
Here is a good example of a non-trival setup.py for cx_Freeze: http://www.pythonexample.com/code/cx_freeze-setup/
Is there a workable and proven way to freeze a pyqt4 application in windows? I heard that there are some issues for py2exe.
I used py2exe for a PyQt4 project at work but ended up switching to PyInstaller.
py2exe worked great for the most part. I remember having to manually tell it to include the sip libraries in my setup.py file along with some others depending on the program. PyInstaller seems to handle this better in my opinion, although I often find myself removing DLL files from the final folders' qt4_plugins folder that it has decided to include that I don't actually need. For example, qt4_plugins\imageformats\qjpeg4.dll when I'm not using JPEG files at all. This does not hinder the frozen application in any way, it'll just increases the filesize.
The manual for PyInstaller is pretty good as well and with it's 'Getting Started' section you should quickly be able to get things set up. It's as simple as creating a .spec file per project which is automatically generated but is also a normal Python file so that you have the option to tweak it or add any extra tasks such as code signing or maybe creating a setup.exe program using NSIS.
I have a windows batch file named pybuild.bat in my path who's contents consist of:
python -O c:\python27\pyinstaller-1.5\build.py "%~f1"
so that I can easily build a project from the command line by running 'pybuild projectname.spec' on the projects .spec file. I've also added this to the registry's entry for the .spec file so that I can freeze a project quickly from Explorer:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.SPEC\shell\Freeze\command]
#="C:\\Python27\\Scripts\\pybuild.bat \"%1\""
My main reason for switching from py2exe though is that some users complained that the frozen apps would not run on their machines. I kept running into the error:
The application has failed to start
because the application configuration
is incorrect. Reinstalling the
application may fix the problem.
but only on some machines, usually running Windows XP. I found that getting the user to install the Microsoft Visual C++ 2008 Runtimes made the problem go away.
Frozen apps created with PyInstaller didn't have this problem as it seems to package these runtimes into the output folder. If UPX is available somewhere in your path it will compress your DLL and PYD files as well, resulting in a smaller output folder.
Long story short - both py2exe and PyInstaller work fine. I hit a few issues with py2exe when using it and although there may be workarounds for these if you hunt around I found that PyInstaller worked better without any modifications. I've distributed frozen apps from PyInstaller that make use of image and database libraries from PyQt4 as well as a few other third party libraries and haven't hit any problems yet.
I've an python GUI application, I use pyQt4.
I build binary with bbfreeze (before I was using py2exe but it didn't work with email module well).
On system where I build this app, everything works properly, but when I install it on raw windows (without all those vc_redist and set of python libraries) binary does not work.
Where should I start to find a solution, since I have no messages/exceptions/crashes, it simply ends immediately after i run it from command line.
I predict that if I'd install some of tools from "build system" I would run it.
Is this the only way?
I mean, if I would find the missing lib (if it's a lib problem), would adding this library to bbfreeze script would solve this problem?
cheers
P.
Get Dependency Walker, and run depends.exe on your executable. It will examine the full tree of DLL dependencies, and mark with a red error the ones that are missing.
It will likely be a MSCVRTxx.dll.
I have a problem: I used py2exe for my program, and it worked on my computer. I packaged it with Inno Setup (still worked on my computer), but when I sent it to a different computer, I got the following error when trying to run the application: "CreateProcess failed; code 14001." The app won't run.
(Note: I am using wxPython and the multiprocessing module in my program.)
I googled for it a bit and found that the the user should install some MS redistributable something, but I don't want to make life complicated for my users. Is there a solution?
Versions:
Python 2.6.2c1,
py2exe 0.6.9,
Windows XP Pro
You need to include msvcr90.dll, Microsoft.VC90.CRT.manifest, and python.exe.manifest (renamed to [yourappname].exe.manifest) in your install directory. These files will be in the Python26 directory on your system if you installed Python with the "Just for me" option.
Instructions for doing this can be found here.
Don't forget to call multiprocessing.freeze_support() in your main function also, or you will have problems when you start a new process.
While others have discussed including the MSVC runtime in your install package, the above solution works when you only want to distribute a single .zip file containing all your files. It avoids having to create a separate install package when you don't want that additional complication.
You should be able to install that MS redistributable thingy as a part of your InnoSetup setup exe.
When you run py2exe, look closely at the final messages when it's completed. It gives you a list of DLLs that it says are needed by the program, but that py2exe doesn't automatically bundle.
Many in the list are reliably available on any Windows install, but there will be a few that you should manually bundle into your Inno Setup installation. Some are only needed if you want to deploy on older Windows installs e.g. Win 2000 or earlier.
You can ship the runtime DLLs in question with your application as a "private assembly". This simply means putting a copy of a specially-named directory containing the runtime DLLs and their manifests alongside your executable.
See my answer to this post.