py2exe problems - python

c:\python26\setup.py py2exe
Trying to run py2exe and when I get to command prompt I run the line above. However as opposed to converting my file it try's to open it. What am I doing wrong?

You must create your own setup.py and then run it with py2exe:
c:\my_python_scripts>python setup.py py2exe
In your setup.py you import distutils, py2exe and show names of your scripts to compile. There is template for it. Then I usually create .bat file which compiles my scripts.
Have you read py2exe tutorial?

Related

How to convert Python project into executable

I have a Python project that I want to convert into an executable. I have installed Pyinstaller. I only know how to convert one single script into .exe, but I have multiple packages with multiple python scripts.
The command line I used with success is:
pyinstaller --noupx --onefile --add-data="cprofiles.ui;." cprofiles_lmfit.py
pyinstaller manages relatively well the multiple '.py' files that you import, no need to cite them. Under the 'add-data' option, you list the non-py files and in my example, the 'cprofiles_lmfit.py' file is the one containing the main.
But as indicated here need help to compile python with pyinstaller (and in few other posts), I am a beginner with pyinstaller. I was never able to use the 'theano' module and I did not optimize. I still have to test the suggestions in the answer.
Converting the main script into .exe should solve the problem, use -onefile to convert it to one exe and rest of the .py files should be included.
1) Open the command prompt
2) Install pyinstaller
Pip install pyinstaller
3) Test your python script first just to check python script should work with normal
.py extension. Saurabh is the name of python file
python saurabh.py
4) Convert the python into executable file
pyinstaller --onefile Saurabh.py
Notice we have passed “–onefile” as a argument which tell pyinstaller to create only one file
5) Go to directory and navigate to the dist folder.
Prerequisite : Install PyQt5 to avoid error.
pip install PyQt5

How to convert a pygame application with multiple modules to .exe

I have a pygame application which I would like to convert to .exe format.
Pygame2exe (https://pygame.org/wiki/Pygame2exe) works nicely EXCEPT I am unable to figure out how to do this conversion with a project that has more than one custom module.
For example:
python_project/
main.py
other.py
I need to compile both modules, and merging them is not an option.
I have been working at this problem for a few weeks, and have not found any solutions.
I know it is possible, because I had it working, and then formatted the only hard drive that had a copy of the code without realizing I had not made a backup.
EDIT
Thank you Michael.
I just had to make a small change to the setup.py file you provided to make it font compatible. Here is the full setup.py file
from distutils.core import setup
import py2exe
import os
origIsSystemDLL = py2exe.build_exe.isSystemDLL
def isSystemDLL(pathname):
if os.path.basename(pathname).lower() in ["sdl_ttf.dll"]:
return 0
return origIsSystemDLL(pathname)
py2exe.build_exe.isSystemDLL = isSystemDLL
setup(windows=['main.py'])
(taken from Pygame font not working after py2exe)
Thanks again.
if you are using python 3.3 or 3.4, you can use py2exe.
install through pip, pip install py2exe in cmd
note: if 'pip' is not recognized as an internal or external command, navigate to the directory in which python is installed,/scripts probably: C:\python34\scripts
make a setup script called setup.py,
with just the three lines of code
from distutils.core import setup
import py2exe
setup(windows=['filename.pyw'] #probably pyw in windows, will be name of main file
then open command prompt in the directory where the main file and setup.py are located, and type setup.py py2exe
DO NOT USE or filename.pyw in the setup script, use the name of the main module.
this will make a folder called dist, (you can safely get rid of '__pycache_') containing all the files your exe needs to run!
you will probably want to make an installer, I would recommend Inno Setup (http://www.jrsoftware.org/isinfo.php)

Convert a Python (3.5.2) File into an exe?

is there any surefire way to convert a Python (3.5.2) File into an exe? I have seen Pyinstaller, py2exe and cx_Freeze. cx_Freeze does not have a Python 3.5 version, only 3.4 so it isnt compatible. Py2exe works only for Python 2 and while I had some success with Pyinstaller, it returned an error relating to 9130 WARNING: hidden import "pygame._view" not found! (the only one as I can see).
The exe. file was created but malfunctioned and stopped working.
Any advice?
I used py2exe to convert python 3 files to exe files. I haven't tested with version 3.5 but this website says that this version of py2exe works with any python 3 versions.
Download and install py2exe
Navigate to your python folder.
Create new text file called setup.
Insert these commands:
from distutils.core import setup
import py2exe
setup(console=['nameofyourpyfile.py'])
Close the text file and open cmd.
Navigate to your python folder using command cd.
Enter this command: python setup.txt py2exe
Press enter and your done navigate to folder called dist and find your exe file.
If it doesn't work install program called pywin32 and try again. If pywin32 doesn't help then let me know I will help you for sure :D

Python to EXE file in one file

So far I have used cx_freeze to convert .py file to .exe file, but I get many files. Is there a way to get it all into one executable?
I have seen that PyInstallerGUI is able to that, but it is for Python 2.7. Can it be done with Python 3.4 as well?
PyInstaller works up to Python 3.5. Once you've installed it (type in your terminal pip install pyinstaller), you can do in your terminal:
pyinstaller --onefile script.py
where script.py is the name of script you want to compile into .exe
With the --onefile option it will create only one .exe file.
I haven't tried it but, PyInstaller says here it can do that and it supports Python 2.7 and Python 3.3+.
Quoting from the linked page:
PyInstaller can bundle your script and all its dependencies into a
single executable named myscript (myscript.exe in Windows).
The advantage is that your users get something they understand, a
single executable to launch. A disadvantage is that any related files
such as a README must be distributed separately. Also, the single
executable is a little slower to start up than the one-folder bundle.
Before you attempt to bundle to one file, make sure your app works
correctly when bundled to one folder. It is is much easier to diagnose
problems in one-folder mode.
I found this in the PyInstaller documentation:
pyinstaller --onefile your-python-file.py
To find more: PyInstaller documentation

Creating an executable file from python script

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.

Categories

Resources