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.
Related
So, I've created a build for my Kivy app with PyInstaller that stores all of its dependencies into a folder in /dist/ and that can be executed from within that folder. This is about as far as Kivy's Windows packaging tutorial goes.
The most promising tutorial that I could find using PyInstaller alone was this one. However, none of the attempted python -m PyInstaller app_name.spec rebuilds produced anything that compressed everything down to one file. Also, the --onefile packages were over 200MB in size, when all of the code and dependencies (including another EXE) aren't anywhere near that size altogether, on top of not running.
Is there a straightforward way of using, say, .NET Core or some other program to compress the PyInstaller's tutorial-produced package and all of its dependencies into a single executable (.EXE)? I know of NSIS, but my goal is not to have the source code sit visibly anywhere on end users' devices.
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/
I created a Python script for a Freelance job and I can't find how to compile/build/package it for easy sharing. The person for which I created it is not a technical one, so I can't explain him how to activate a virtualenv, install requirements and so on.
What is the easiest way for him to run the project right after downloading it?
Can the whole virtualenv be compiled into an .exe? If yes, can this be done inside a macOS system?
Yes you can package your python programs and it's dependencies with
Cx_Freeze
There are other python modules that do the same, personally i prefer cx_Freeze because it's cross platform and was the only one that worked out of the box for me.
By default cx_Freeze automatically discovers modules and adds them to the exe to be generated. but sometimes this doesn't work and you might have to add them by yourself
To create a simple executable from a file. you can just use the bundled cxfreeze script
cxfreeze hello.py --target-dir dist
but more for more complex applications that have different files you'll have to create a distutils setup script.
Note that cx_freeze doesn't compile your code like a traditional compiler. it simply zips your python files and all it's dependencies ( as byte code) together, and includes the python interpreter to make your program run. So your code can be disassembled. (if anyone wants to) and you'll also notice that the size of your program would be larger than it was initially (Because of the extra files included)
I ended up using PyInstaller as this worked out of the box for me.
I'm using cxFreeze to freeze my Python application. All seems to be working as expected but peering into the build directory got me thinking...
Is there a way I could have fewer files in the build directory?
Currently, there's a bunch of PYD files and the necessary DLL files lying around. Then I have some configuration files (custom) and the rest of the stuff is thrown into a library.zip file. Is there a way I could bundle pretty much everything into the library.zip file so I could have fewer files in there?
(This seems to be more a-nice-clean-directory fetish than a real "issue" but nonetheless, sometimes you've just got to fulfill the curiosity/fetish)
Thanks a ton guys (in advance).
PyInstaller is cross-platform too, and has more features than cx_Freeze, but doesn't support Python 3. See also py2exe - generate single executable file.
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.