Skip to content

Running Python script from a command prompt

December 9, 2009

Create the file in a text editor (I’m using Emacs).  For example, here’s a text file I called

#! /usr/bin/env python

print "Hello, world!"

Now we need to make the file executable.  In the command line, type:

$ chmod a+x

Then you should be able to run it like this:


In order for this to work (running the script directly from the command line), the directory containing the script must be defined in the env PATH variable (to check path type echo $PATH).  Since this is *not* usually the case, ie, the directory you’re working in is defined as a PATH variable, the program can be run like this: ./  Doing this tells the interpreter to look in the current directory (./).

I used these links to help me with this stuff:

How do I make a Python script executable on unix?

Executable Python scripts

As well as Beginning Python.

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: