B.Mr.W.
B.Mr.W.

Reputation: 19628

Python Import From Specific Location (Multiple Libraries Installed)

I have installed a library say (mylib) to the default installation directory /usr/bin/... and then, I installed the same library to a different folder by using:

python setup.py install --prefix=/tmp/python/

so, right now, I have TWO EXACTLY THE SAME library installed on different folders.

However, I don't want to delete either of them. I want to call the version which is from the /tmp/python/mylib, how could I do it in my python script.

#PSEUDO CODE
mypath = "/tmp/python/"
import mypath.mylib
...

Upvotes: 1

Views: 1132

Answers (1)

Leonid Shvechikov
Leonid Shvechikov

Reputation: 3997

You could do:

import sys
sys.path.insert(0, '/tmp/python/')

import mylib

Or change environment variable PATH when run the script:

$ PATH=/tmp/python/ you_script

But it is better to use virtualenv. And virtualenvwrapper maybe.

Upvotes: 2

Related Questions