Creating an executable file from python script

2020-07-19 05:52发布

问题:

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

回答1:

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


回答2:

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.



回答3:

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.