3 Replies - 26289 Views - Last Post: 23 June 2009 - 01:07 AM Rate Topic: -----

#1 xZachtmx  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 125
  • Joined: 14-June 09

How to make python script into a linux executable.

Post icon  Posted 18 June 2009 - 03:37 PM

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?
Is This A Good Question/Topic? 0
  • +

Replies To: How to make python script into a linux executable.

#2 thesilentenigma  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 5
  • Joined: 07-May 09

Re: How to make python script into a linux executable.

Posted 22 June 2009 - 01:26 AM

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


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

$./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.
Was This Post Helpful? 1
  • +
  • -

#3 code_m  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 24
  • View blog
  • Posts: 202
  • Joined: 21-April 09

Re: How to make python script into a linux executable.

Posted 22 June 2009 - 07:42 PM

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:
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 June 2009 - 07:45 PM

Was This Post Helpful? 1

#4 Marty[ni]  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 10
  • Joined: 22-June 09

Re: How to make python script into a linux executable.

Posted 23 June 2009 - 01:07 AM

The Cog said:

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
Was This Post Helpful? 2

Page 1 of 1