I have made a python file and converted it to executable file with pyinstaller in Ubuntu, now I want to run the same executable file in windows, how would I do that?
Oups... Programs exists in different formats, normally text (.py for Python), byte code (.pyc) for Python and native executable formats. Text is normally portable across any architecture except for possible charset conversions. Byte code is normally portable, I am sure for Java, less for Python because I have never used it. But native executable formats (true executable in Linux or .exe files on Windows) are dedicated to one single architecture.
So a program generated by pyinstaller on Ubuntu can only be used on a Linux system with same system libraries as yours (read Ubuntu same version, even if it should also run on some other Linux flavours), but definitely not on Windows.
You have to install pyinstaller on windows, and run pyinstaller on windows (From the OS that you want to build your exe file)
Related
How to make python program standalone executable under linux
I have done some research but I am not looking for a way to make a script and run the .py file like answered in this question. What do I use on linux to make a python program executable
I am looking to "complie" the .py to a standalone program so users in a linux environment like ubuntu can run it out of the box without installing python and the libraries I used because no root access.
I found py2exe for windows. I would think there is a way to achieve this in linux?
Doesn't pyinstaller compile under the OS you are using?
if you want a windows exe - use pyinstaller in windows environment...
For Linux, use pyinstaller in Linux.
You can use Jython to compile it to JVM. Using the Jython compiler
jythonc [options] [module]*
This would, however, require Java to be installed...
There are also a couple of other resources to compile Python. From Compiling Python Code, some cross-platform tools are
Gordon McMillan’s installer (cross-platform)
Anthony Tuininga’s cx_Freeze (cross-platform)
but I do not know anything about those.
I used the recent version pyinstaller with the option --onefile to create one stand alone file of my python script. On my Mac it works just fine if I open the file in the terminal (bash shell), but in the Linux bash I get the following error
bash: ./myprog: cannot execute binary file
Is there something I am missing here?
pyinstaller creates an executable that will work on the machine it is run on. So if you run pyinstaller on Windows, it creates an executable for Windows. Same for Mac, Linux, etc, so I'd try running pyinstaller on your Linux box to produce a working executable for that environment. Mac executables are not Linux executables.
This is because (as I understand it) the underlying Python includes platform-specific implementations of certain things. For instance, the os module has a bunch of conditional, platform-dependent imports that will be bundled into the executable. Since it only has access to whatever binaries are available on the platform pyinstaller is running on, it can't produce a version for other platforms.
Linux checks magic number of executable file,
magic number of a Linux executable file starts with "DLE elf"
execute "od -c YUPUR_FILE" and see result
I've been searching through SO for a while now trying to come up with an answer to this but due to my inexperience with programming I don't understand much of the documentation, nor am I confident enough to experiment too much.
Would anyone be able to describe in slightly simpler terms how I would use programs like Py2exe, PyInstaller, cx_freeze etc.? I just want a way for others (mainly friends) to be able to run my (simple, text only) program without having to download python themselves. If there is an easier way to do this I'd appreciate knowing that too.
Running Vista 32bit, python 2.7
There are two distinct ways of freezing python scripts to create executables:
Packing the interpreter and *.pyc files into one exe file-container. Such an approach is used by tools like PyInstaller, Py2exe, cx_freeze.
Creating native code from Python source, usually using a middle step of converting Python-source to C or C++ code. This is done by such tools as Shed-skin and Nuitka. The problem of this aproach is that such tools do not always support all the functionality of Python (e.g. they can have some typing limitations and so on)
The point where you have to start is reading the documentation. Such tools are not just push-and-run style tools, they usually have some configuration that must be implemented (that's the problem of possibly all build systems, and as the project grows, the configuration and number of hooks also grows).
You can start with Py2exe tutorial and 'hello-world' to get acquainted with that how compilation is done. As far as I know it's a simplest way to get your goal.
And the last thing, you can't create cross-platform native executables as their file formats are strongly operating system and hardware dependent.
Download py2exe
Download this msvcp90.dll
Copy your FileCode.py AND msvcp90.dll to C:\Python27\
In C:\Python27\ create new text file, then enter this code inside it:
from distutils.core import setup
import py2exe
setup(console=['Avril.py'])
Replace Avril.py with YourFileName.py
Save the file as setup.txt
Open CMD and type this:
cd C:\Python27\
python setup.txt py2exe
Now go to C:\Python27\dist\ and there's your .exe program.
Source: Manvir Singh
Python scripts can be made directly executable, like shell scripts, by putting the python environment path in the top of the script file.
#!/usr/bin/env python3.5
The Python installer automatically associates .py files with python.exe so that a double-click on a Python file will run it as a script. The extension can also be .pyw, in that case, the console window that normally appears is suppressed.
Detailed description also for linux is here.
Install pyinstaller, a program that converts .py to .exe for python 2.7 to where python is located:
cd C:\python27\scripts
pip install pyinstaller
then move whatever python file you want to compile to C:\python27\scripts, compile from there by using:
pyinstaller --onefile yourfile.py
the --onefile is optional but it packages the whole thing(in this example yourfile.py) into one .exe. Once everything is done there will be 2 new folders along with a .spec file. From C:\python27\scripts open the folder dist. Your .exe will be located there in one file which you can double tap to execute and distribute to anyone who doesn't have python. Hope it helps.
I was using c shell of unix. I have created a script in python with file extension .py.
Now I want to convert this .py file into an .exe file in unix's c shell.
I found that py2exe package will not work for csh, but there is freeze.py which I could use to convert says Google.
But I am unable to use this in my case. When I use python freeze.py hello.py it raises an error: freeze.py not found
Is there any other way to it in UNIX.
The simple answer is "No". Although there is an option: use WINE with PyInstaller.
PyInstaller is a program that converts (packages) Python programs into
stand-alone executables, under Windows, Linux, Mac OS X, Solaris and
AIX. Its main advantages over similar tools are that PyInstaller works
with any version of Python since 2.2, it builds smaller executables
thanks to transparent compression, it is fully multi-platform, and use
the OS support to load the dynamic libraries, thus ensuring full
compatibility.
is there any way to converts Python scripts into executable Windows programs on linux
i know py2exe and pyinstall will work well on windows
but i only has linux Environment
Why would you want to convert it to a windows executable on a linux platform? Anyway, I'd say you have two options:
Use py2exe with wine (a Windows emulator). I've done this, and it works
If that is not possible, you could try pyinstaller. I haven't tried it, but it seems to be sort of the same, but multi-platform
cx_Freeze will do you the job.
http://cx-freeze.sourceforge.net/