tags:

views:

36

answers:

3

How do you guys go about storing your python modules locally? And how do you then go about referencing them in your python scripts?

Should I do this?

/home/python/modules

And then create a sub-directory for each module, like say the amazon s3 module:

/home/python/modules/amazon-s3/s3.py

Now I have to somehow tell python to look at these folders for modules, which I think is sys.path somehow?

+2  A: 

I usually store my modules in /usr/local/lib/python for the whole system, and /home/user/lib/python for the user. That's if they weren't installed via the system package manager. If they were a .deb or .rpm or whatever, they'll probably be placed in /usr/lib/python, as per the FHS standard, which specifies where different types of files should go on a POSIXish operating system.

Set the PYTHONPATH environment variable to have local packages be found by the interpreter.

Borealid
Could you show how to do the PYTHONPATH part? Thanks
JGord
@JGord: how to set environment variables depends on the shell you're using, but something like this will generally work: `PYTHONPATH=/home/user/lib/python python foo.py`
Borealid
@Borealid ok so you put all .py files in the same directory, you don't create sub-directories?
Blankman
@Blankman: No, when you run the package's `setup.py` it will usually create subdirectories for you. Most packages come with a `foo.py` and a `foo/` directory; `foo.py` just includes the appropriate stuff from the subdirectory.
Borealid
what if the person didn't build a package, they just have a .py file.
Blankman
@Blankman: If you just have one .py file, why would it need a subdirectory?
Borealid
it wouldn't your right, just want to know my options in organizing things.
Blankman
A: 

Should I do this?

No.

Install them in site-packages, just like it says in the documentation.

http://docs.python.org/install/

http://docs.python.org/library/site.html

S.Lott
A: 

If you're particularly concerned about managing python modules you'll probably want to look at virtualenv, which lets you setup separate virtual python environments so you can separate out what modules are installed and used.

Parand