I'm trying to create a self-contained version of pisa (html to pdf converter, latest version), but I can't succeed due to several errors. I've tried py2exe, bb-freeze and cxfreeze.
This has to be in windows, which makes my life a bit harder. I remember that a couple of months ago the author had a zip file containing the install, but now it's gone, leaving me only with the python dependent way.
How would you work this out?
Check out pyinstaller, it makes standalone executables (as in one .EXE file, and that's it).
Related
I have a small program I am trying pass around to friends. It includes nonstandard libraries like the PIL and mtTkinter packages, and thus usually requires them to be included in the pythonpath.
Is there a way I can generate the the .pyc file so that all required code for the program to run is included in the file, and not required to be installed on my friends computers. I want this to be able to work between different OS like windows, mac, and linux.
Does it have to a pyc file? I use pyinstaller to package programs and share. The first time I used it, I couldn't believe how easy it is.
Here's a link to the portion on packaging for multiple operating systems: https://pyinstaller.readthedocs.io/en/stable/usage.html#supporting-multiple-operating-systems
I have generated an .exe-file for a little PowerPoint Tool, that I've written using python 3.6, the PyQt5 framework and pyinstaller. The program runs without any errors on my own laptop and functions as expected.
Unfortunately, I can't get the .exe to run on a different computer. I've tried with 2 other computers now and get different errors on each of them.
PC 1:
Entry Point not found
The procedure entry point ucrtbase.terminate could not be
located in the dynamic link library api-ms-win-crt-runtime-l1-1-0.dll.
PC 2:
This application failed to start because it could not load the Qt platform plugin 'Windows'.
The thing, that bugs me is, that I had this last error (from PC2) during development on my dev computer, but fixed this problem for my own PC.
What I was trying to do is create an .exe-file that just runs on any PC. It's a simple PowerPoint Helper, which is supposed to be a quick tool to create new slides from a folder of images. That is why it's pretty important, that it can be seamlessly used. Ideally just opening the .exe and go, without the need to worry about individual missing pieces on every single computer, where it will be utilized.
BIG QUESTION: Is there anything I can do, to guarantee my .exe to include all the dependencies that are needed to run?
Things I've tried (aka I DID try to solve it myself.. for days):
read trough here: https://github.com/pyqt/python-qt5/issues/2
changed my .specas mentioned here: https://github.com/carlosperate/pyinstaller-test/blob/master/package/pyqt5_test.spec
read through all of this: https://stackoverflow.com/search?page=2&tab=Relevance&q=entry%20point%20not%20found
and this: https://stackoverflow.com/search?q=qt+platform+windows
and this: pyinstaller exe without any dependencies?
But nothing helps.... Most of the posts address problems when compiling the executable file, but this works just fine for me.
If using Python 3.5, PyInstaller 3.3.1 and PyQt 5.9.2 is an option for you, use fbs instead of PyInstaller to freeze your application. It is based on PyInstaller but solves edge cases like the one you are experiencing. There are instructions for setting up your app for use with fbs here.
I've noticed this question several times on SO, but none of the answers seems to be applicable to a Python 3.6 version. As most cases when this is asked, I accidentally deleted my .py source file but I still have a .exe built with pyinstaller (passing only the --onefile and --icon arguments).
I managed to reach the following point:
Ran pyinstxtractor.py on the .exe I mentioned above. This gave me a bunch of files including one with no extension which is actually the .pyc of the source file missing the magic number.
Renamed the file with no extension in order to have the .pyc extension
Used a hex editor to append the magic number to the .pyc file, using the header from another .pyc file (used __future__ for this example). It looks like this.
Ran uncompyle6 on the .pyc file that now has the correct magic number, but the operations fails as seen here. Some of the code is retrieved(about 15%) but this important part is just obfuscated byte-code.
Any other tools I managed to come across do not work on Python 3.6 such as Easy Python Decompiler, unpyclib, pyREtic.
I did not manage to use pycdc/Decompyle++ or Maynard as I don't understand how they work, but they still don't seem to support 3.6.
Anything else I might try?
PS: My OS is Win7 and I did try file recovery software and system rollbacks, none of which worked.
I started to fiddle with PyQt, and made a "beautiful" script from the pyqt whitepaper example app (pastebin)
It works perfectly in Windows and Linux (with qt environment already installed on both).
Now my question is: Since I am trying to use Qt because it is compiled (at least pure old C++ based Qt), how can I compile some .exe file to run it on Windows, or a standalone executable for Linux.
The point is that I want the program to be compiled, because of speed and portability, instead of interpreted from source, which would require a previous setup on any machine. One of the goals, for example, is sending small gui scripts via email to coworkers who are not programmers at all.
if you want completelly create one stand alone executable, you can try PyInstaller . i feel it's better to create one stand alone executable than cx_freeze or py2exe (in my experience). and easy to use (full documentation available in the site).
It supports Python 3.6 or newer.
Pass the --onefile argument if you want to create completely standalone .exe. in example :
pyinstaller.exe --onefile --windowed app.py
After spending many weeks on this and trying all the alternatives - PyInstaller, py2exe, cx_freeze,... - I created my own library: https://build-system.fman.io/. It is based on PyInstaller but solves many of its common pain points. It also lets you create native installers on Windows, Mac and Linux.
You may want to check out cx_freeze. It claims to create executables which are "cross platform and should work on any platform that Python itself works on."
I came across it in exploring the moneyGuru package which uses PyQt. I downloaded the moneyguru.exe file to my Windows XP system, executed it, and it worked fine on Python 3.2.
You can clone the hg repo from here to see how it.s done.
There is a module named Py2EXE, which will do exactly what you want to do. It will convert the script into a .exe file to run on windows. I'm not sure about linux, but I bet there is a module out there somewhere.
py2exe.com
I am using pyinstaller
pip install pyinstaller
I don't know, but pyinstaller does't append sip.pyd. So, your need a PyQt5\sip.pyd. I recommend nice windows style qwindowvistastyle.dll.
Make build.cmd file as:
pyinstaller --onefile --clean ^
--add-binary="C:\Users\Quazer\.virtualenv\pyqt5-36\Lib\site-packages\PyQt5\sip.pyd;PyQt5" ^
--add-binary="C:\Users\Quazer\.virtualenv\pyqt5-36\Lib\site-packages\PyQt5\Qt\plugins\styles\qwindowsvistastyle.dll;PyQt5\Qt\plugins\styles" ^
.\main.py
^ - new line in command file (.cmd, .bat)
Since I am trying to use Qt because it is compiled
You're defeating this benefit by using Python. Although the other answers give an introduction to the options for distributing Python code without requiring users to install Python themselves, Python is intended to be an interpreted language so there will be downsides to each of these options (ex. speed, program size, compatibility, etc...). They may or may not be deal-breakers to you.
Your two other options are:
Embrace the interpreted nature of Python: have people you're sharing your program with install Python and the dependencies. You can simplify this process significantly though. Ex. on Linux, use a package manager.
Write your program in C++. Doing so would allow you to truly compile a single, native executable. This unfortunately means dropping Python, but there's reasons people still write code in less beautiful languages like C++ and it sounds like you might be running into some of them.
All of the python I've written so far have been fine on my own computer, but now I'd like to send some programs to friends to have them test certain features. Suppose I wrote an application in python with wxpython. Assuming people I send code to will not have either installed, what is the best way to include both python, and the wxpython library so the other person isn't struggling to get it running? I've never had to do this at this point in my learning and would love some feedback!
Thanks.
You can create a bundle using py2exe and installer using NSIS and ship it as executable so that your friend will get the complete working executable. But mind you, this will increase the size of the file enormously and I have often found it easier to ask them to install via README.txt files.
There are lots of binary builders: py2exe, cx_freeze, bbfreeze, PyInstaller, GUI2Exe. I have a whole slew of articles on these:
http://www.blog.pythonlibrary.org/2010/08/31/another-gui2exe-tutorial-build-a-binary-series/
http://www.blog.pythonlibrary.org/2010/07/31/a-py2exe-tutorial-build-a-binary-series/
http://www.blog.pythonlibrary.org/2010/08/19/a-bbfreeze-tutorial-build-a-binary-series/
http://www.blog.pythonlibrary.org/2010/08/12/a-cx_freeze-tutorial-build-a-binary-series/
http://www.blog.pythonlibrary.org/2010/08/10/a-pyinstaller-tutorial-build-a-binary-series/
Unless they are going to develop with Python too, then I don't see any reason for them to want to install a bunch of multi-megabyte installers versus your own. You can read about how to use Inno Setup to create an installer here:
http://www.blog.pythonlibrary.org/2008/08/27/packaging-wxpymail-for-distribution/