I have two Python scripts, one as User Interface and one as background process. I need both of them because there is a sub-process and the UI. However I want it together get a executable.
I tried it with py2exe, which can only compile one of them.
Next I used pyinstaller but that has the same problem
pyinstaller user_interface.py
# and with py2exe
from distutils.core import setup
import py2exe
setup(console=['hello.py'])
What you need to do is some kind of packaging. First try to create a package using setup.py which you can use directly through python console by importing that package. and then you can create an executable out of it. Please refer the example in mentioned link.
Please refer this link: real python tutorial
You can write a small launcher script that spawns both processes, and then package that file.
I never used py2exe or pyinstaller, so I don't know how python dependencies are managed. If having code split in several files is a problem, then you can just concatenate you two existing scripts and the launcher in one single file.
Related
I am coding a PyQt5 based GUI application needs to be able to create and run arbitrary Python scripts at runtime. If I convert this application to a .exe, the main GUI Window will run properly. However, I do not know how I can run the short .py scripts that my application creates. Is it possible to runs these without a system wide Python installation?
I don't want ways to compile my python application to exe. This problem relates to generated .py scripts
No, to run a Python file you need an interpreter.
It is possible that your main application can contain a Python interpreter so that you don't need to depend on a system-wide Python installation.
No, it won't work. But you can make a small tool that will load the scripts and eval them within the context of packed executable. Look here for more details. One thing to be mindful of is that your eval executable should import all the dependencies needed by your generated .py files
NOTE: Before marking this as duplicate please read the whole post first
I'm trying for hours to convert my python 3.6 code to exe, I've searched everywhere and tried everything, the most helpful place was there:
Best method of converting .py to .exe for Python 3.6?
So apparently there are only 3 ways of converting py to exe:
PyInstaller
Py2exe
Cxfreeze
Pyinstaller doesn't support Python 3.6, and py2exe is very outdated.
As for cxfreeze, it sounds like it supports Python 3.6, so that's the route that I've taken.
I've searched everywhere on how to use cxfreeze, unfortunately, all guides that I have found seem to be outdated:
http://cx-freeze.readthedocs.io/en/latest/overview.html this guide for example has three routes, two of which doesn't work (The first gives me a .spec file that i dont know what to do with it and the second gives me an error because i dont have the cxfreeze.util module) and the 3rd is too complicated for my tastes
How do I use cx_freeze? this uses the second route, still it doesn't work
I'm not allowed to comment for some reason, so this isn't really an answer, but for my part I installed cx_Freeze from https://pypi.python.org/pypi/cx_Freeze
When you install it, there's an extra step that's not documented. Using the Windows CMD shell, go to your python installation directory, into the Scripts sub-directory and you will find a few files called cxfreeze...
You need to create the batch file by typing python cxfreeze-postinstall
A file called cxfreeze.bat will be created which you can move into your main python folder or wherever your python program is located.
Then type cxfreeze mypythonprogram.py --target-dir dist
This should create a working exe in the dist directory. However, it doesn't work for me as I get an error in the finder.py file which is part of the cxfreeze installation so I don't know if I've done something wrong or this version is completely buggy.
edit: by commenting out line 561 in the finder.py file (C:\Python\Python36-32\Lib\site-packages\cx_Freeze\finder.py on my system) I was able to run it and Generate the EXE which appears to run OK.
I need to be able to send someone a python program but they dont have python, is there a way to compile the python program and open it as a normal computer program.
Any help would be appreciated
Yes, you can use cxfreeze. Documents are here.
Gist of them is that you need to create a distutils setup file to specify which modules are required and any other resources that should be included. You can then run python setup.py build to create your build application.
As mentioned in the docs, you can then use something like inno setup to make an .exe file from the output of cxfreeze.
It's been a while since I've used it but I can look back over how I set it up if you need any more help getting it running.
I've been searching through SO for a while now trying to come up with an answer to this but due to my inexperience with programming I don't understand much of the documentation, nor am I confident enough to experiment too much.
Would anyone be able to describe in slightly simpler terms how I would use programs like Py2exe, PyInstaller, cx_freeze etc.? I just want a way for others (mainly friends) to be able to run my (simple, text only) program without having to download python themselves. If there is an easier way to do this I'd appreciate knowing that too.
Running Vista 32bit, python 2.7
There are two distinct ways of freezing python scripts to create executables:
Packing the interpreter and *.pyc files into one exe file-container. Such an approach is used by tools like PyInstaller, Py2exe, cx_freeze.
Creating native code from Python source, usually using a middle step of converting Python-source to C or C++ code. This is done by such tools as Shed-skin and Nuitka. The problem of this aproach is that such tools do not always support all the functionality of Python (e.g. they can have some typing limitations and so on)
The point where you have to start is reading the documentation. Such tools are not just push-and-run style tools, they usually have some configuration that must be implemented (that's the problem of possibly all build systems, and as the project grows, the configuration and number of hooks also grows).
You can start with Py2exe tutorial and 'hello-world' to get acquainted with that how compilation is done. As far as I know it's a simplest way to get your goal.
And the last thing, you can't create cross-platform native executables as their file formats are strongly operating system and hardware dependent.
Download py2exe
Download this msvcp90.dll
Copy your FileCode.py AND msvcp90.dll to C:\Python27\
In C:\Python27\ create new text file, then enter this code inside it:
from distutils.core import setup
import py2exe
setup(console=['Avril.py'])
Replace Avril.py with YourFileName.py
Save the file as setup.txt
Open CMD and type this:
cd C:\Python27\
python setup.txt py2exe
Now go to C:\Python27\dist\ and there's your .exe program.
Source: Manvir Singh
Python scripts can be made directly executable, like shell scripts, by putting the python environment path in the top of the script file.
#!/usr/bin/env python3.5
The Python installer automatically associates .py files with python.exe so that a double-click on a Python file will run it as a script. The extension can also be .pyw, in that case, the console window that normally appears is suppressed.
Detailed description also for linux is here.
Install pyinstaller, a program that converts .py to .exe for python 2.7 to where python is located:
cd C:\python27\scripts
pip install pyinstaller
then move whatever python file you want to compile to C:\python27\scripts, compile from there by using:
pyinstaller --onefile yourfile.py
the --onefile is optional but it packages the whole thing(in this example yourfile.py) into one .exe. Once everything is done there will be 2 new folders along with a .spec file. From C:\python27\scripts open the folder dist. Your .exe will be located there in one file which you can double tap to execute and distribute to anyone who doesn't have python. Hope it helps.
I have created a GUI program using python and wxpython. It is now ready to be turned into an executable file. I have tried for the last two days following various instructions from py2exe. All instructions for Command Prompt refer to older versions of windows and I'm using windows 7. I have never used Command Prompt before as I'm still new to programming. Is py2exe going to best way to create an executable file or is there a better option?
I have followed instructions on creating a setup.py file and it reads:
from distutils.core import setup
import py2exe
setup(windows = ["Core.py"])
When I enter the command in Command Prompt:
C:\Python27\Cylinderdrawer\python setup.py py2exe
I get the following:
'C:\Python27\Cylinderdrawer\python' is not recognized as an internal or eternal command, operable program or batch file
There are more than two options. You can use py2exe, PyInstaller, cx_freeze and bb_freeze. I enjoy using the GUI2Exe wrapper script that wraps all of these plus py2app (for Macs) as it makes tweaking the settings a breeze.
As far as I can tell, cx_freeze, PyInstaller and bb_freeze have the newest releases with py2exe's last release in 2008.
As for your issue, it sounds like you don't have Python on your system path. Try typing out the full path to your python instead. Something like this:
c:\python27\python.exe setup.py py2exe
I don't know what "Cylinderdrawer" is, but that is NOT a standard location for the Python executable on Windows.
See also:
a py2exe tutorial
a GUI2Exe tutorial
a cx_freeze tutorial
a bb_freeze tutorial
a PyInstaller tutorial
Your two options are py2exe and cx_freeze. py2exe is more widely used, and it can be tricky to get all the details right. If you provide details about what is going wrong, we might be able to help.
Thanks everyone for their help. As much as I have not worked it out completely yet, this problem has been solved. I'll ask seperatly about the subsequent problem if I cannot work it out. For anyone else having a similar problem the following is how I solved it.
C:\Python27\Cylinderdrawer\python setup.py py2exe
This was what I originally put into Command Prompt. Cylinderdrawer is my project folder. This is wrong it needs to be where python.exe is located. the next part, i.e., "setup.py" is the setup file. The only way I could get it to work was to explicitly state where the file was. Bellow is the command that worked.
C:\Python27\python "C:\Python27\Cylinderdrawer\setup.py" py2exe
Once again, thanks to all those who helped.