How to put .py in .exe? [duplicate] - python

This question already has answers here:
How can I convert a .py to .exe for Python?
(8 answers)
Closed 2 years ago.
I have Python 3.6 and I did a project in .py that I would like to put in an .exe document ;
How can I do that ? I tried Py2exe but it did not worked due to my python version.
Thanks for your answers.
Traftmine

I faced this problem some times ago, after a lot of googling I found the best solution for me.
Alternatives
Py2Exe: Which is old, the last release on PyPi is on 21 October 2014.
pyInstaller: Is a nice tool, but with some problem that we will see later.
auto-py-to-exe: Use pyInstaller to build the .exe, so suffer the same problem, but has a nice GUI and is intuitive to use.
cx_Freeze: I think the best solution, because it was the only one that works in my case, it is also recommended from python
Investigation
During this time I looked on google and StackOverflow for the best solution, each time that I found something it was out-dated or not well explained/documented, so I studied the official docs.
py2exe
As first try I installed py2exe it seems the best option, also recommended from python, so, give it a try.
All goes fine during the installation process, so I decide to follow the tutorial and get my .exe.
During the step 3 of the tutorial, running setup I received an error, looking on google I found this.
I gave up with py2exe.
auto-py-to-exe && pyInstaller
I have installed auto-py-to-exe and all went good, the program open without problems so I create my .exe file, that works!
The only problem was that, the program works only on my laptop, on all the other machine where I try to execute the antivirus delete it.
Looking on google I found the github repository where I found one issue like the mine, reading it I understand that the problem is pyInstaller.
Looking on the pyInstaller repository I found one issue where one contributors tells to contact the antivirus vendor, so I gave up again.
cx_Freeze
Looking the docs it seems to be overcomplicated realize a simple .exe, so I have studied the documentation and found what I need.
Open you project folder and create inside it a setup.py file with inside:
from sys import executable
from cx_Freeze import setup, Executable
setup(name='programName', version='0.1', description='my fancy description')
Setting up this file require a little bit of study, there are multiple options to set. You can set the option to create a simple .exe or also the create a windows/mac/linux installer.
Once you have your file ready, with the options that you need, just open a shell/terminal/cmd in the directory where the setup.py file is located and execute: python setup.py build
Now in your project folder you will see a folder where inside you can find your .exe file.

You should check out PyInstaller.

Related

.exe generated with pyinstaller crashes on other PCs - how to create .exe with TRULY no dependencies?

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.

PyInstaller: how to create multiple programs in one folder?

I'm developing a Python package and have about 10 demo Python scripts that show its capabilities.
I want to distribute the demo scripts with PyInstaller: create 10 exe files and put them in one folder with all libraries they depend on.
Cannot you tell me, how can it be done?
This feature is present in pyinstaller, but unfortunately it is broken in since version 3.0
This bug report states it will not be included in the 3.4 release either.
py2exe can do this. I found it a little harder to use than pyinstaller but for this application is probably right.
This has been answered in another stackoverflow question and I suggest going there for more details.

py2exe difficulties [duplicate]

This question already has answers here:
a good python to exe compiler? [closed]
(3 answers)
Closed 9 years ago.
With some useful answers of my previous question (See below), I decided to give py2exe another try.
I tried the tutorial from py2exe.org (http://www.py2exe.org/index.cgi/Tutorial), but got an error at step 3. I did 1 and 2 exactly as told, and put both files (hello.py and setup.py) in my main folder where I installed python in: D:\Programs\Python.
When running the 'code' form step 3 I got the following error, totally on the bottom of the output:
"ImportError: DLL load failed: %1 is not a valid Win32-application.*"
I've got a screenshot of the entire output, but I don't know where to upload it.
Extra information:
I have 64bit Windows 7 (profesional) and Python 2.7.3 (first I had 3.3.0, but downgraded because of some reasons). It is not a big problem for me to change to another version. I downloaded py2exe 0.6.9.
Note: I couldn't choose between py2exe for 32- or 64bit. I guess then a error should show up earlier, but it might be handy to know.
*I literally translated the last part from Dutch, so it can be slightly different then English pc's.
Previous question:
What is the easiest .py to .exe converter?
I've tried a few converters, of which cx_Freeze and py2exe. Using cx_Freeze was too complicated (I couldn't find a good tutorial) and py2exe gave some errors. Before I'm going to try to understand one of these two or try another one, I want some input which converter you think is the best, and I need a good tutorial.
I have barely experience with cmd, and am quite a newbie if it comes to programming/python, so I am looking for the easiest-to-use converter.
If you say I really need some cmd experience, please direct me to a cmd tutorial/course.
you can use GUI2exe that's the easiest way im my opinion !
You wont learn much about the converter's but it gets the job done without any problems.
ps. GUI2exe isnt a converter , its a gui to use the converters!
What kind of erros does py2exe give you? That is what I use and it works like a charm for me.
I've used py2exe previously. I assume you've looked at the tutorial on the py2exe project page?
There is also a good one available on the Python Library page.
I used py2exe for complicated Python/Qt/PyQt applications. The biggest thing you'll need to know about that is that the MSVCP90.dll file is needed. You can get that from Microsoft. You'll then need to copy it and the other files mentioned in it's license to the Python DLLs directory. Detailed instructions are available on the py2exe tutorial (Step 5)
Try py2exe and cx-freeze. These are the two most common ones you'll find out there. Most others are generally a derivative of cx-freeze

Pygame Distribution - Runtime Error

I am working on a problem with my 2D arcade game programed with Python using the module pygame for 2 days now and I can't find a solution.
The problem is: I want to create a Windows Executable File that is running my program correctly. I already managed to create a .exe file, but I get an error as soon as I start the exe:
Runtime Error!
Path\MyGame.exe
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
I tried to create the .exe file with every module that makes it easy to build one, for example cx_freeze, py2exe, pyinstaller. At the end it doesnt matter which one I have used, I got the same error. I already tried to start the .exe file with another PC, it failed. Updated my Microsoft Visual C++ Redistributable, nothing helped.
So the fault must be somewhere in my code. The program is running correctly, but there must be something that prevents me from making a .exe file that works fine.
The code has around 1000 lines, I know it's too much to ask for someone checking the whole code but I hope someone had a similiar problem to this or have some tips why this error is appearing and can help me.
You can find the code here.
The problem is not your code, the problem is how you generate your .exe. Doing that with pygame is a real bitch, but with some hacking and google'ing you can do it.
This should get you started: http://pygame.org/wiki/Pygame2exe
Had similar problems and that one too. Found a way to solve them:
After few weeks (had this problem even before) I'm happy to say that I solved this problem! :)
1st part of my problem (http://i.stack.imgur.com/WpkjR.png):
I solved it by editing setup.py script with adding "excludes" part in it. That resulted in successful making of executable file!
Modified setup.py script:
from distutils.core import setup
import py2exe
setup(windows=['source_static.py'], options={
"py2exe": {
"excludes": ["OpenGL.GL", "Numeric", "copyreg", "itertools.imap", "numpy", "pkg_resources", "queue", "winreg", "pygame.SRCALPHA", "pygame.sdlmain_osx"],
}
}
)
So, if you have similar issues, just put those "missing" modules into this "excludes" line.
2nd part:
After I succeeded in making of executable file, I had next problem: "The application has requested the Runtime to terminate it in unusual way. Please contact...". After days and days of searching and thinking how to solve this another problem, I found a way to do it. I couldn't believe that the problem was so absurd. The problem was in my code, with font definition:
font1 = pygame.font.SysFont(None, 13)
After changing "None" to some system font name (for an example "Arial" (must be a string)), and compiling, I couldn't believe that my .exe file worked!
font1 = pygame.font.SysFont("Arial", 13)
Of course, you can use your own font, but you must specify its path and define it in your program.
So for all of you who are experiencing this issues, try this steps and I hope that you will succeed.
I really hope that this will help you, because I've lost days and weeks trying to solve these problems. I even tried making my .exe file with all versions of python and pygame, with many other .exe builders and setup scripts, but without luck. Besides these problems, I had many other problems before but I found answers to them on stackoverflow.com.
I'm happy that I found a way to solve this problems and to help you if you are faced with the same ones.
Small tips (things I've also done):
1st: update your Microsoft Visual C++ library to the latest one.
2nd: if you have images or fonts similar that your executable program needs, include them to dist folder (where your .exe file has been created).
3rd: when you are making your .exe file, include all needed files to the folder where your setup.py script is (all files and directories that your main script uses).
Used Python 2.7 x64, pygame and py2exe.
Had the same problem, solved it by putting pygame's default font file in the distribution folder. It was used in project, and I'd assumed it would be included in the build automatically.

Including python and other files

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/

Categories