1

Am pretty new to python although have programmed a lot before. I'm using mac osx snow leopard and python 2.6.1.

I've followed this post about setting your PYTHONPATH to a custom scripts directory but can't get python to recognise it. How can I run my python script from the terminal in Mac OS X without having to type the full path?

So i've got a simple helloworld script in /Users/richn/Documents/scripts/ called hello.py

Inside is this

#!/usr/bin/env python

print "Hello World!"

I've created a .profile file in my home directory with this in it

export PYTHONPATH=/Users/richn/Documents/scripts

I've also changed permissions of the file to make it executable with chmod a+x hello.py

Running ./hello.py in the terminal from that scripts folder works fine however whenever i run it outside of that folder i get this error

-bash: ./hello.py: No such file or directory

How can i get my scripts to run outside of that folder? Anyone got any ideas?

Thanks very much

1
  • You want your terminal to pick up the file, not your Python interpreter, so you should be updating PATH not PYTHONPATH. Commented Apr 6, 2012 at 8:17

1 Answer 1

3

What you'll want to do is to edit your PATH variable which is a list of directories your command shell checks when you run a command that does not begin with / or ./ rather than PYTHONPATH:

export PATH="$PATH:/Users/richn/Documents/scripts"

After you have exported your PATH variable you should be able to confirm that it has exported correctly:

echo $PATH

and afterwards you should be able to run "hello.py" successfully.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.