i'm newbie for python programming, i'm having a .py file, now what shall i do so i can create an application from .py file and it can be istall and run in any linux pc, i try to packaging it but its just create .tar file where i need python to run it, is it any to do so,
thanks
Make sure that the main python file has #! /usr/bin/env python as the first line, then make sure it has execute permission set (should be as easy as chmod +x file_name.py).
From link:
"PyInstaller is a program that converts (packages) Python programs into stand-alone executables, under Windows, Linux, and Mac OS X. Its main advantages over similar tools are that PyInstaller works with any version of Python since 1.5, 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."
I have not used it never in linux so I can not give you more info
I think any modern Linux OS has Python installed, so you can just ditribute the .py file if it has no weird dependencies.
Related
Made a python script in Ubuntu, but I read that pyinstaller compiles based on the operating system, so if I compile it on Ubuntu, it'll be for Ubuntu. How can I make an executable in Ubuntu, for Windows, or do I have to export my script into my Windows OS and compile it there?
From PyInstaller’s documentation:
If you need to distribute your application for more than one OS, for example both Windows and Mac OS X, you must install PyInstaller on each platform and bundle your app separately on each.
So, yes, you generally must run PyInstaller on the operating system the emitted binary will be run on. The documentation does suggest using a virtual machine and that running PyInstaller with WINE may work.
I want to make a portable app that would have some code and python executable that would run on any Windows even if python is not installed.
I would like it to be python 3.6 and so it has only pip and setup tools installed.
EDIT: concerning duplicate
not quite. I don't want to compile the code. I wanted to give them .py files but realize that Windows won't have python installed on default. I want something that can be carry on a flash drive but will run my code from source not binary.
Please correct me, if I understood it wrong. I think there are at least two ways to do it.
suppose you have one portable_run.py script you want to run everywhere on a flashdisk.
Make a exe file with pyinstaller for example. you can get a exe file like portable_run.exe. On target windows system what you need to do is to run the exe direcltly protable_run.exe
Use a portable python distribution like winpython or python-xy. you just need to copy this portable distribution on the flash disk together with your portable_run.py. To run it on target system flashdisk/path-of-winpython/python portable_run.py
Hopefully it could give you some idea.
I also encountered the same problem and managed to create a portable python with Python's official Windows embeddable package.
I wrote the steps into a ps1 script so I can easily repeat the process without going through the pain.
The steps:
Download the portablepy.ps1 from the repo :
https://github.com/Dreamsavior/portable-python-maker
Create a blank folder, put the portablepy.ps1 to that folder.
Execute the portablepy.ps1
The script will create a portable python 3.9.10 with pip in the current folder by default.
To install custom version of Python run the script with -source and -destination parameter
.\portablepy.ps1 -source "https://www.python.org/ftp/python/3.9.10/python-3.9.10-embed-amd64.zip" -destination "C:\SomeDir\PortablePython\"
Where the -source is the url of the Python's Windows embeddable package from this page: https://www.python.org/downloads/windows/
And -destination is the path of your folder (ended with backslash).
I think my question is quite badly phrased, which may be why I haven't been able to find the answer yet.
I created my program in Python, created an installable .exe file from it using bdist_winisnt. Once the program is installed, I would like to be able to run it from anywhere. It's a command line program, so I would like the user to be able to be in a different directory and still be able to type example.py in command line and the program can run.
Is this possible? Is there a way of including some kind of path instruction in the setup.py which will be run on install so that the computer will always know where it is?
I would also like to be able to do this in Linux at some point, will it work the same?
I'm very new to programming, so I may have made some mistakes with what I have said, apologies in advance.
EDIT: turns out there was a really simple way to do it by adding one line to the setup.py file
Good answer to your question is: http://docs.python-guide.org/en/latest/shipping/freezing/
Options are:
bbFreeze
py2exe (supports Python 3)
pyInstaller (does not support Python 3)
cx_Freeze
py2app (Mac)
Your installer only copies the python script to a specified directory.
In order to run a python script you need to have python installed.
You can use a tool like PyInstaller to convert your script (.py file) into an executable (.exe on windows). The way that works is PyInstaller copies both the python interpretor and your script into a single file so that you can distribuite your program easily.
After you have converted your script into an executable, you need to add it to the path so that your operating system knows where to find it. After you do that, you can run your program from the command line from any directory.
The same process will also work on Linux, but you'd have to make separate distributions of the executable because windows executables are different from linux executables.
Check PyInstaller
PyInstaller is promising solution for creation of executables.
I have tested it on Ubuntu, but documentation claims, MS Windows is supported too.
There are multiple options, one of them being single executable file (which include complete Python).
I have a python script "MAlice.py" (main) which depends upon several other scripts including yacc.py and lex.py and whatever they in turn import.
I don't have a lot of experience writing makefiles and I'm wondering how I can produce an executable called "compile" using this code, so that someone could call:
make
./compile "someTestFile.alice"
I'm working in Ubuntu.
I think what you are looking for is a way to package your python project into a self-contained executable. It is not a compiling process but rather just a bundling into a portable environment. This will include your python interpreter.
You can look into pyinstaller for linux or windows. And py2app for osx (pyinstaller would work on osx as well to create just a single file)
If what you are after is the ability to provide a source package to someone and for them to be able to run a build command, and have an executable entry poiny called "compile", then what you want is simply a setuptools script. This will install all the declared dependencies and will create any named entry points you define.
http://packages.python.org/an_example_pypi_project/setuptools.html
Python scripts aren't compiled; they're interpreted. You can turn MAlice.py itself into an executable script by adding this as the very first line:
#!/usr/bin/env python
And making the script executable:
chmod a+x MAlice.py
So then you can simply run it like this:
./MAlice.py "someTestFile.alice"
I need to run python in an environment where there wont be python. Is it possible to execute python as an executable in Unix Environments, like HP-UX, IBM-AIX, Solaris, Linux etc etc....
The targeted OS is AIX now.... since it does not have python support and the installation is difficult......
Thanks.
I have used http://www.pyinstaller.org/ to create an executable in ubuntu. look at their manual, it also have the cool feature of outputting just one file with --onefile. My first choice was freeze but the executable failed to run when I used some external modules - I could not solve it and I found pyinstaller to be perfect for me.