This question already has answers here:
What do the python file extensions, .pyc .pyd .pyo stand for?
(3 answers)
Closed 9 years ago.
I am new to python. I am using ubuntu for software development using python. Here python extension in ubuntu.
ubuntu :
.py
.pyc
Windows:
?
Mac :
?
and also please explain the extensions.
They are the same. In both windows and mac, you have .py files and compiled .pyc files. They are the same on all operating systems.
You might also occasionally meet .pyo, which is the same as a .pyc but it has been optimized. What that means really is that all assert statements are removed (used in testing software).
However, .pyd is specifically for windows. You can learn more about it from here.
UPDATE
There is also .pyw for pythonw programs on Windows - these do not generate a Windows console
-- From cdarke
Related
This question already has answers here:
How exactly is Python Bytecode Run in CPython?
(4 answers)
Closed 2 years ago.
Is it possible to run python bytecode files without the need of the C Python interpreter to be installed on the host OS ?
No, python interpreter is required.
You can use apps such as pyinstaller to make a executable of your scripts so that all required packages and python libs including the interpreter is self contained in a single executable. It runs like any other programs so nothing else needs to be done except double click and run.
Also .pyc files require the specific version of python to run with which they are compiled so it is really not a recommended way of distributing python code if thats what you are planning.
This answer has more details: https://stackoverflow.com/a/36027342/4289062
This question already has answers here:
Create a directly-executable cross-platform GUI app using Python
(13 answers)
How to deploy Python to Windows users?
(4 answers)
Create a single executable from a Python project [closed]
(3 answers)
Closed 9 years ago.
I've used several modules to make EXEs for Python, but I'm not sure if I'm doing it right.
How should I go about this, and why? Please base your answers on personal experience, and provide references where necessary.
Auto PY to EXE - A .py to .exe converter using a simple graphical interface built using Eel and PyInstaller in Python.
py2exe is probably what you want, but it only works on Windows.
PyInstaller works on Windows and Linux.
Py2app works on the Mac.
I found this presentation to be very helpfull.
How I Distribute Python applications on Windows - py2exe & InnoSetup
From the site:
There are many deployment options for
Python code. I'll share what has
worked well for me on Windows,
packaging command line tools and
services using py2exe and InnoSetup.
I'll demonstrate a simple build script
which creates windows binaries and an
InnoSetup installer in one step. In
addition, I'll go over common errors
which come up when using py2exe and
hints on troubleshooting them. This is
a short talk, so there will be a
follow-up Open Space session to share
experience and help each other solve
distribution problems.
Also known as Frozen Binaries but not the same as as the output of a true compiler- they run byte code through a virtual machine (PVM). Run the same as a compiled program just larger because the program is being compiled along with the PVM. Py2exe can freeze standalone programs that use the tkinter, PMW, wxPython, and PyGTK GUI libraties; programs that use the pygame game programming toolkit; win32com client programs; and more.
The Stackless Python system is a standard CPython implementation variant that does not save state on the C language call stack. This makes Python more easy to port to small stack architectures, provides efficient multiprocessing options, and fosters novel programming structures such as coroutines. Other systems of study that are working on future development: Pyrex is working on the Cython system, the Parrot project, the PyPy is working on replacing the PVM altogether, and of course the founder of Python is working with Google to get Python to run 5 times faster than C with the Unladen Swallow project. In short, py2exe is the easiest and Cython is more efficient for now until these projects improve the Python Virtual Machine (PVM) for standalone files.
Not on the freehackers list is gui2exe which can be used to build standalone Windows executables, Linux applications and Mac OS application bundles and plugins starting from Python scripts.
Use cx_Freeze to make exe your python program
py2exe:
py2exe is a Python Distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation.
See a short list of python packaging tools on FreeHackers.org.
This question already has answers here:
Create a directly-executable cross-platform GUI app using Python
(13 answers)
Closed 8 years ago.
I wrote a small program in Python. Actually it's not even a program really :p.
It's just this:
print(1+1)
When I saved it, it saved it as py1.py (a python file). And apparently, Python files can be executed, and it executed fine.
Is there anyway to be able to compile it into bytecode? Also is there a way to make it a stand alone application?
I could be getting terms wrong, I'm more of a Java person. I'm new to Python.
Thanks!
First of all, as #emh pointed out this is a duplicate of several other questions. One of them is stackoverflow.com/questions/2933/an-executable-python-app
There are several sets of scripts and modules that are available that allow you to convert a .py file into an standalone executable file. Some of the more popular ones are py2exe, py2app, Pyinstaller, and Cx_freeze. The one that is best for you depends you how you are using it. First, it depends on what operating you are using. py2exe is meant specifically for creating .exe files or windows executable files, py2app is the same as py2exe except it builds .app files for Mac OS, pyinstaller and cx_freeze can build an executable for multiple systems, including Windows, Mac OS, and Linux. Next, what you use depends on what version of Python you have. Cx_Freeze is the only one that I mentioned that supports python 3.X; the others only support Python 2.X. The advantage pyinstaller has, is it builds all the dependent files into one executable file that unpacks right before execution, whereas the others create a folder with lots dependent files along with the executable file. I use Cx_freeze, because of its python 3.x support and relatively easy building process.
As for converting it to bytecode, there are a couple python modules for this. One is py_compile. an example of this is:
import py_compile
py_compile.compile('filepathandname')
this will create a .pyc file, which python will put in a folder labeled __pycache__ in the same directory as the original file.
Hope this helped.
This question already has answers here:
Create a single executable from a Python project [closed]
(3 answers)
Closed 8 years ago.
I have noticed that there are several commercially available programs I have that are partially made in python, but they worked even before I downloaded python. Do they somehow incorporate the interpreter into the executable? How?
Obviously this is platform dependent, but on Windows for example, the Python on Windows FAQ suggests the following "See http://www.py2exe.org/ for a distutils extension that allows you to create console and GUI executables from Python code."
There are a number of packages out there that bundle a py script with its runtime dependancies (ie python & any 3rd party modules)
py2exe
pyinstaller
cx_freeze
py2exe has sort of died a death (I use to use this)
pyinstaller is in active development and has some very nice features BUT does not support py3 at the moment
cx_freeze is equally nice and does support PY3
My preference right now is pyinstaller and is partly why I have held of fully converting a suite of py programs I have to py3
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Distributing Python programs
I have several source codes for some GUI programs I made in Python. I'd like to distribute them. However, I'd like to make it as easy as possible for the end user to get the program up and running. What are the common way's of going about this problem?
This is in reference to Windows XP and on.
All noteworthy linux distributions and Mac OS come shipped with some version of Python. Windows don't have Python installed by default, so you must install it separately in order to run a Python module. Of course the installed Python version must be the same as your program (version 2 or 3).
The easiest way to distribute your program is to just distribute the source code (e.g. send your module by email or upload it somewhere) but in that case, the target PC must have Python installed and meet the dependencies. An even better solution (at least for the community) is to upload your program as a package on PyPi. More info for that procedure can be found HERE.
In some cases there are reasons that prevent you from using these options. For example you can't install python and/or the dependencies (no root/admin account). If that is the case, you can bundle your module(s) along with everything else that is required to run your program (e.g python*.dll on windows). As far as i know the basic options for this kind of distribution are the following ones:
PyInstaller
briefcase
fbs
PyOxidizer
nuitka --standalone
py2app (only for Mac OS)
cx_Freeze
freeze
py2exe
cython --embed
Another approach would be to use Portable Python or in case of Linux/BSD StaticPython
Note : Not all of the aforementioned tools run on all platforms or/and support Python3. Check their documentation.
Unmaintained ones
bbFreeze
esky (unmaintained)
vendorID
gui2exe
You want py2exe, which is an extension of the distutils package.
http://www.py2exe.org/