Hi, I've just paid £10 for a book on the internet with the sole intention of solving one problem, unfortunately 2.5 hours later I am no further forward, despite the fact that the book suggests just a single line of code can achieve my aim. Maybe someone here can help.

I've created very simple python programs using Textwrangler and saved them into a folder called Python. This 'Python' folder, is in the 'Documents' folder, which is in turn in my home directory 'paulpatterson'. Each time I open terminal I immediately want to be able to run these programs without first changing the directory to 'Python' (currently, the only way I can do it). The book says I need to go into nano and edit the .bash_profile by entering the single line:

export PATH=$PATH:~/Documents/Python

However when I do this (and then close and reopen terminal) and type in "python file.py" I get told no such file or directory exists. Can anyone help?

Note - though I'm new to nano, I don't think the problem lies here since I have successfully used it to change other terminal settings when I start a new session.



Recommended Answers

All 8 Replies

Try replacing ~ with $HOME

Also prove

python -m file.py

You could also do an alias for python or script file in your home directory or ¨/bin directory.

With proper setup your Linux (??) can recognize .py files automatically and should run them without needing the python in front.


Thanks for the response. Unfortunately I still can't get the file to run. Since my initial post I'm coming to the conclusion that the problem is to do with the type of file I'm trying to run rather than a problem with adding the path. When I type in

echo $PATH

Terminal gives me a list of all my current paths and this does include the one I've been trying to add so this doesn't appear to be the problem.

How about response if you just type


without python? And the python -m?


If I just type in


as soon as terminal opens it get the following:
-bash: /Users/paulpatterson/Documents/Python/recap.py: Permission denied

if i type in

python -m file.py

I get:
/usr/bin/python: No module named file

Permission denied

So you have maybe not execute rights for the files.

How about after

chmod a+x /Users/paulpatterson/Documents/Python/*.py


sudo chmod a+x /Users/paulpatterson/Documents/Python/*.py

where do I type those in?

In the terminal


Seems like we're getting a bit closer. Doesn't say access denied, but does list a couple of errors in the file.

Paul-Pattersons-MacBook-Pro Thu Jul 01 recap.py
/Users/paulpatterson/Documents/Python/recap.py: line 1: syntax error near unexpected token `('
/Users/paulpatterson/Documents/Python/recap.py: line 1: `start_num = int(raw_input("What number do you wish to start counting at?"))'

But the file runs perfectly if I move it to the home (paulpatterson) directory.
Anyway, thanks for your help on this. Don't know where you are but fast approaching midnight here so off to bed.

Thanks again,


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.