Python importer path

How to Ask Python to create a local library directory

Page 1 of 1

5 Replies - 1765 Views - Last Post: 19 January 2010 - 05:05 PM Rate Topic: -----

#1 code_m  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 24
  • View blog
  • Posts: 202
  • Joined: 21-April 09

Python importer path

Post icon  Posted 04 January 2010 - 11:07 AM

Does anyone know how to go about asking python to create a directory to add into the importer path ?

Like I want to be able to ask python to create $HOME/.local/lib/python3.1/site-packages for me. I am trying to create a program that will serve as a general setup.py program, and I want to be able to use that user library directory as a "local install" option.

If no one knows how python goes about creating such a directory, would it be safe to create it myself, say using os.makedir() ?

(and no, I'm not making up the term importer path, look up sys.sys.path_importer_cache)

Is This A Good Question/Topic? 0
  • +

Replies To: Python importer path

#2 girasquid  Icon User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: Python importer path

Posted 04 January 2010 - 12:22 PM

It sounds like virtualenv might be what you're looking for, if I'm understanding you correctly.
Was This Post Helpful? 0
  • +
  • -

#3 code_m  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 24
  • View blog
  • Posts: 202
  • Joined: 21-April 09

Re: Python importer path

Posted 04 January 2010 - 04:34 PM

That seems like it would do the job, but I really want python itself to do it (ie in the std lib), one of my goals is to make this able to run on any python version (including 3.x). Also it seems to be overkill for the simple task I want to complete here, which is to simply create a library directory if it doesn't exist.

... I suppose I have a lot of reading to do :D

This post has been edited by code_m: 04 January 2010 - 05:04 PM

Was This Post Helpful? 0
  • +
  • -

#4 girasquid  Icon User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: Python importer path

Posted 05 January 2010 - 11:12 AM

virtualenv is sort of the de facto 'standard' for doing this when you're using Python in web situations - you might have 6 sites on a server that all need different versions of the same libraries, so you just create virtualenvs for each one and assign their libraries that way.

When I first found out about virtualenv, it sort of felt like overkill - but once you get used to using it, you'll find it's really useful for preventing library conflicts.
Was This Post Helpful? 0
  • +
  • -

#5 code_m  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 24
  • View blog
  • Posts: 202
  • Joined: 21-April 09

Re: Python importer path

Posted 08 January 2010 - 04:39 PM

But I'm not importing from multiple locations, I'm just installing to a single location...

eh, I might give it a shot.... Really nothing more than just a challenge for myself.... I mean I hope it catches on, but that's just a dream at this point :P
Was This Post Helpful? 0
  • +
  • -

#6 programble  Icon User is offline

  • (cons :dic :head)

Reputation: 49
  • View blog
  • Posts: 1,315
  • Joined: 21-February 09

Re: Python importer path

Posted 19 January 2010 - 05:05 PM

To import a module from a specific directory, you can
import sys
sys.path.append("/path/to/modules/")
import someModuleInThatPathUpThere


Was This Post Helpful? 1

Page 1 of 1