I just installed a linux system (Kubuntu) and was wondering if there is a program to make python programs executable for linux.
I just installed a linux system (Kubuntu) and was wondering if there is a program to make python programs executable for linux.
Just put this in the first line of your script :
#!/usr/bin/env python
Make the file executable with
chmod +x myfile.py
Execute with
./myfile.py
If one want to make executable hello.py
first find the path where python is in your os with : which python
it usually resides under "/usr/bin/python" folder.
at the very first line of hello.py one should add : #!/usr/bin/python
then through linux command chmod
one should just make it executable like : chmod +x hello.py
and execute with ./hello.py
I do the following:
This essentially turns the file into a bash executable. When you double-click it, it should run. This works in Unix-based systems.
Another way to do it could be by creating an alias. For example in terminal write:
alias printhello='python /home/hello_world.py'
Writing printhello will run hello_world.py, but this is only temporary.
To make aliases permanent, you have to add them to bashrc, you can edit it by writing this in the terminal:
gedit ~/.bashrc
Do the following steps:
#!/usr/bin/python
chmod +x <script-name>.py
<script-name>.py from /usr/local/binln -s <path-to-your-script> /usr/local/bin/<executable-name-you-want>
These steps works irrespective of whether you have single standalone python script or if you have multiple dependent script called by your main file.