Install libraries in a different dir
I want to install pygame on my system, but I don't want to mix the standard libraries with third-party libs. If I install pygame on a different path, how can I then modify 开发者_运维问答sys.path
so the interpreter would know where to look?
It may be overkill, but did you consider using virtualenv? It would let you have a virtual Python installation that used the standard for everything except the libraries you want to keep separate.
You can set PYTHONPATH
to a directory with additional modules. And if you use Python 2.6 or newer, you can just use the default per-user module directory without additional configuration.
I usually use this trick:
import sys
sys.path.insert(0,"..")
import pygame # it will look for pygame in ../ first.
精彩评论