So I have a Python script:
myscript.py
I am executing it like this:
python D:\myscript.py
However, I must have Python installed and included in the PATH
environment variable for that to work.
Is it somehow possible to "bundle" Python executable with a Python script so other people will be able to run it on their PCs without Python?
It is ok if it will work only in Windows.
EDIT:
After trying the compile.py
I get this error:
Traceback (most recent call last):
File "D:\stuff\compile.py", line 4, in <module>
import py2exe
ImportError: No module named py2exe
Here is a list of them.
You want something like py2exe.
Go to Notepad++ Menu, Plugins --> Python Script --> Show Console. In newly opened console window, at bottom type..... execfile('C:/path/to/your/python/file/code.py') #Use forward slash (/) instead of backwared slash. Hit return or click on run button.
PyInstaller has worked well for me, generating reasonably small packages due to its use of upx. Its dependency detection was better than py2exe at the time as well. It seems not to have a lot of recent development and probably doesn't work with 3.x, however.
The source in the repository is a better starting point than the 1.4 package.
Also see the wiki page about working with Python 2.6+.
From the features list:
Here is one way to do it (for Windows, using
py2exe
).First, install the
py2exe
on your Windows box.Then create a python script named
compile.py
, like this:To compile your Python script into a Windows executable, run this script with your program as its argument:
It will spit out a binary executable (EXE) with a Python interpreter compiled inside. You can then just distribute this executable file.
There are multiple solutions like py2exe, cx-freeze or (only for Mac OS X) py2app.