Configuring Python to use additional locations for site-packages

后端 未结 2 1590
鱼传尺愫
鱼传尺愫 2020-12-13 02:16

Is there a way to tell Python about additional site-packages locations without modifying existing scripts?

On my CentOS 5.5 server I have a Python 2.7 i

相关标签:
2条回答
  • 2020-12-13 02:32

    You can use the Site-specific configuration hook.

    "A path configuration file is a file whose name has the form name.pth and exists in one of the four directories mentioned above; its contents are additional items (one per line) to be added to sys.path."

    In your case, you should be able to achieve what you want by simply dropping in a .pth file containing the path of the directory to include:

    [root@home]$ echo "/usr/local/lib/python2.7/site-packages/" > /opt/python2.7.2/lib/python2.7/site-packages/usrlocal.pth
    
    0 讨论(0)
  • 2020-12-13 02:39

    You could replace the python executable with a wrapper script which appends your added installpath to PYTHONPATH. But this is a kludge.

    But I'd try to fix the installation of the add-on so that it properly goes into the site-packages dir.

    0 讨论(0)
提交回复
热议问题