问题
I think my question is quite badly phrased, which may be why I haven't been able to find the answer yet.
I created my program in Python, created an installable .exe file from it using bdist_winisnt. Once the program is installed, I would like to be able to run it from anywhere. It's a command line program, so I would like the user to be able to be in a different directory and still be able to type example.py in command line and the program can run.
Is this possible? Is there a way of including some kind of path instruction in the setup.py which will be run on install so that the computer will always know where it is?
I would also like to be able to do this in Linux at some point, will it work the same?
I'm very new to programming, so I may have made some mistakes with what I have said, apologies in advance.
EDIT: turns out there was a really simple way to do it by adding one line to the setup.py file
回答1:
Your installer only copies the python script to a specified directory.
In order to run a python script you need to have python installed.
You can use a tool like PyInstaller to convert your script (.py file) into an executable (.exe on windows). The way that works is PyInstaller copies both the python interpretor and your script into a single file so that you can distribuite your program easily.
After you have converted your script into an executable, you need to add it to the path so that your operating system knows where to find it. After you do that, you can run your program from the command line from any directory.
The same process will also work on Linux, but you'd have to make separate distributions of the executable because windows executables are different from linux executables.
回答2:
Good answer to your question is: http://docs.python-guide.org/en/latest/shipping/freezing/
Options are:
- bbFreeze
- py2exe (supports Python 3)
- pyInstaller (does not support Python 3)
- cx_Freeze
- py2app (Mac)
回答3:
Check PyInstaller
PyInstaller
is promising solution for creation of executables.
I have tested it on Ubuntu, but documentation claims, MS Windows is supported too.
There are multiple options, one of them being single executable file (which include complete Python).
来源:https://stackoverflow.com/questions/24783462/is-it-possible-to-create-a-python-program-distributable-for-windows-that-can-be