user10296334
user10296334

Reputation:

Python program to run on PC

I have written a python program which gets an input from user then runs a code and returns values, it is being saved as .py extension.

I want to run it on different PC which doesn't have python. Is there a way to save it or compile it to .exe?

Note: I am used to writing C programs which are directly compiled (code blocks) and gives .exe

Upvotes: 0

Views: 115

Answers (3)

Jonas Wolff
Jonas Wolff

Reputation: 2244

I use py2exe but options like cx_freeze and pyinstaller are also out there. What goes for mac i beleive there exist a module called py2app ;)

to use py2exe you must first have python 3.4 since it hasnt't recently been updated. After that you need to make a file in which you write

from distutils.core import setup
import py2exe

setup(windows=["yourfile"])

then you need to run the file with the following command - i called the file setup.txt here.

py -3.4 setup.txt install

remember to write .py if you used a python file and then you just need one more step

py -3.4 setup.txt py2exe

and ofcause remeber you need to have py2exe installed. If you haven't before you do anything write in to the comandoprompt

pip install py2exe

The exe will then be found i the dist folder.

Upvotes: 0

Philip DiSarro
Philip DiSarro

Reputation: 1025

The C code that you are used to writing compiles into .exe as you already know. However, not every PC can run .exe files, ie. those running on Mac, and other operating systems. So in short, the answer is no. However, there is a branch of Python known as Jython, which runs on the JVM (Java Virtual Machine) allowing it to work on any operating system with any PC. The ability to work on any machine in any environment is one of the most prized features of Java, and with Jython (which is compiled to Java code) you are able to emulate this key feature with python.

Upvotes: 0

Emac
Emac

Reputation: 1167

Pip install PyInstaller and then in the command prompt do PyInstaller yourscript.py > nameofprogramyouwant.exe

Upvotes: 1

Related Questions