Reputation: 728
Okay, I am tearing my hair out trying to do this. I've read through dozens of webpages and they've all given me contradictory information, and none of what they've told me to do has worked.
I have a folder full of scripts I downloaded that will only work if they're part of the pythonpath. I want to either move the folder itself into the default path or temporarily (not permanently) add /desktop/search to the path.
What is the default path, and how would I do the latter?
Upvotes: 0
Views: 264
Reputation: 85045
The canonical UNIX approach would be to ensure each of the scripts has a proper shebang line, perhaps:
#!/usr/bin/env python2.7
and then installed with the proper permissions (i.e. including execute
permission) in a directory on your shell search PATH
, perhaps /usr/local/bin
. Then you can invoke a script just with its name:
scriptname
The pythonic approach would be to install the scripts using Distutils/easy_install
/pip
into one of the standard site-packages
locations for your Python instance and then be able to invoke a script with something like:
python2.7 -m scriptname
But that may require some work to get everything set up. The first approach is probably easier.
The bottom-line is that you can't really do exactly what you asked for, that is, be able to type python scriptname
when the scriptflle can be in an arbitrary directory.
Upvotes: 1
Reputation: 147
You can add this to the beginning of your python file.
import sys
sys.path.append("/Users/<username>/Desktop/search")
Upvotes: 1