Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run pythons as .exe files without python installed

Tags:

python

py2exe

I'm trying to run a python file on a system without python installed. I'm using py2exe, which gives me a .pyc file which runs fine on my system, but when I give it to a friend without python it tells him Windows can't run the file.

My setup.py file contains this;

from distutils.core import setup
import py2exe

setup(console=['PyVersionControl.py'])

When I run py2exe in the commandline, this is output

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\chdick>python setup.py py2exe
running py2exe

  3 missing Modules
  ------------------
? readline                            imported from cmd, code, pdb
? win32api                            imported from platform
? win32con                            imported from platform
Building 'dist\PyVersionControl.exe'.
Building shared code archive 'dist\library.zip'.
Copy c:\windows\system32\python34.dll to dist
Copy C:\Python34\DLLs\pyexpat.pyd to dist\pyexpat.pyd
Copy C:\Python34\DLLs\_ctypes.pyd to dist\_ctypes.pyd
Copy C:\Python34\DLLs\unicodedata.pyd to dist\unicodedata.pyd
Copy C:\Python34\DLLs\_hashlib.pyd to dist\_hashlib.pyd
Copy C:\Python34\DLLs\_socket.pyd to dist\_socket.pyd
Copy C:\Python34\DLLs\_tkinter.pyd to dist\_tkinter.pyd
Copy C:\Python34\DLLs\_bz2.pyd to dist\_bz2.pyd
Copy C:\Python34\DLLs\select.pyd to dist\select.pyd
Copy C:\Python34\DLLs\_ssl.pyd to dist\_ssl.pyd
Copy C:\Python34\DLLs\_lzma.pyd to dist\_lzma.pyd
Copy DLL C:\Python34\DLLs\tk86t.dll to dist\
Copy DLL C:\Python34\DLLs\tcl86t.dll to dist\

C:\Users\chdick>
like image 336
CDickson Avatar asked Nov 21 '22 19:11

CDickson


1 Answers

You need to use py2exe to create an executable file from your script (i.e. create script.exe from script.py).

If you have the correct version of py2exe installed, you should be able to type python -m py2exe.build_exe script.py.

See the py2exe package page for details.

like image 91
Tim Henigan Avatar answered Dec 06 '22 14:12

Tim Henigan