What I use in linux to create Python executable

I just installed a Linux system (Kubuntu) and wondered if there is a program to run python executables for Linux.

+69
python linux file-permissions
Nov 20 '08 at 10:27
source share
8 answers

Just put this on the first line of your script:

#!/usr/bin/env python 

Make an executable with

 chmod +x myfile.py 

Run with

 ./myfile.py 
+126
Nov 20 '08 at 10:32
source share

If you want to get a standalone binary application in Python, try using a tool like py2exe or PyInstaller .

+12
Jan 09 '13 at 9:53 on
source share

You can use PyInstaller. It generates a build distribution, so you can execute it as a single β€œbinary” file.

http://pythonhosted.org/PyInstaller/#using-pyinstaller

Python 3 also has a built-in build option:

https://docs.python.org/3/distutils/builtdist.html

+7
Dec 12 '14 at 17:12
source share

Entering these lines at the beginning of the code will tell operating systems to search for the binary program needed to execute the python script ie, this is the python interpreter.

So it depends on your operating system, where it supports the python interpreter. Since I have Ubuntu as an operating system, it supports the python interpreter in /usr/bin/python , so I need to write this line when I run my python script;

 #!/usr/bin/python 

After completing and saving the code

  • Launch your command terminal

  • Make sure the script is in your working directory

  • Type chmod +x script_name.py

  • Now you can run the script by clicking script. A warning window will appear; click "Run" or "Run in terminal" in the warning field; or at the terminal prompt type ./script_name.py

+4
Jan 09 '13 at 7:55
source share

Another way to do this could be to create an alias. For example, in a terminal entry:

 alias printhello='python /home/hello_world.py' 

Writing printhello will run hello_world.py, but this is temporary. To make aliases permanent, you must add them to bashrc, you can edit it by writing this in the terminal:

 gedit ~/.bashrc 
0
Oct 11 '16 at 2:49 on
source share

If you want to make hello.py

first find the path where Python is on your OS with which python : which python

it is usually located in the "/ usr / bin / python" folder.

in the very first line of hello.py you need to add: #!/usr/bin/python

then through linux the chmod

you just need to make it executable, for example: chmod +x hello.py

and execute with ./hello.py

0
Feb 07 '18 at 10:24
source share

I do the following: 1) put #! / Usr / bin / env python3 2) chmod u + x file.py 3) Change .py to .command

Should work

0
May 23 '19 at 1:48
source share

At the top of the code, first write:

#usr/bin/python or #usr/bin/env python Then create a new .sh file called setup.sh and write:

 sudo apt-get install python python-pip sudo chmod +x yourfile.py sudo -H pip install librariesyouwant 

Therefore, we eliminate the problem of the absence of python and the installation of any missing packages. To make a shortcut on the desktop, follow these steps:

 sudo cp yourfile.py ~/Desktop/ sudo chmod +x ~/Desktop/yourfile.py 

Please note that if your code is not created to create a GUI, you will need to run your code from the terminal using ./yourfile.py

-one
Dec 08 '16 at 21:13
source share



All Articles