School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,420 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,527 people online right now. Registration is fast and FREE... Join Now!




How to make python script into a linux executable.

 

How to make python script into a linux executable.

xZachtmx

18 Jun, 2009 - 02:37 PM
Post #1

New D.I.C Head
*

Joined: 14 Jun, 2009
Posts: 38



Thanked: 1 times
My Contributions
Ok i have a program i have completed and its all jsut one python script which makes reference to a sound file. I know py2exe makes windows executables but how can i make linux executables for python scripts?

User is offlineProfile CardPM
+Quote Post


thesilentenigma

RE: How To Make Python Script Into A Linux Executable.

22 Jun, 2009 - 12:26 AM
Post #2

New D.I.C Head
*

Joined: 7 May, 2009
Posts: 5


My Contributions
You would have to give the script executable permission in the following manner:
CODE
$chmod +x script.py


Where script.py would obviously be the name of your script. You would then run the script as follows:

CODE
$./script.py


Note that you would have to do this on every Linux system that the script is intended to run on to give the script executable rights. I hope this answers your question.
User is offlineProfile CardPM
+Quote Post

code_m

RE: How To Make Python Script Into A Linux Executable.

22 Jun, 2009 - 06:42 PM
Post #3

D.I.C Head
**

Joined: 21 Apr, 2009
Posts: 118



Thanked: 8 times
My Contributions
Make sure to put the proper shebang call at the start of the file, otherwise it will be assumed you want the file to use the same shell that you executed it from.

Here's a nice (bash) function to use to create an empty python file:
CODE

function new_py () {
    if [ $# >= 2 ]; then
        echo "#!/usr/bin/env python2" > $1.py;
        chmod "+x" $1.py;
    else
        echo "Usage: new_py <filename>";
    fi;
};


Of course this isn't needed, and you could very easily type this out yourself each time you want to make a new file. (note that "new_py" can be anything, and the shebang assumes that python 2.x is installed somewhere in your $PATH, using the program env, which simply passes a command to your current shell to be executed.)

This post has been edited by code_m: 22 Jun, 2009 - 06:45 PM
User is offlineProfile CardPM
+Quote Post

Marty[ni]

RE: How To Make Python Script Into A Linux Executable.

23 Jun, 2009 - 12:07 AM
Post #4

New D.I.C Head
*

Joined: 22 Jun, 2009
Posts: 10



Thanked: 1 times
My Contributions
QUOTE(The Cog)
Linux (and any unix-like OS) has no naming requirement for program files. Any file can be executable regardless of its name. In fact, the filesystem stores a flag that indicates whether a file is executable, so being executable is a file property just like whether it is readable or writeable, or its name.

An executble file might be a binary executable or might be a script file. If it is a script file, then the first few bytes of the file will be "#!" followed by the name of the interpreter program, e.g.
#!/usr/bin/python
#!/usr/bin/perl
--UbuntuForums.org
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 12:08AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month