简体   繁体   English

如何更改python模块路径

[英]How to change python module path

I install a python2.7.6 locally, and there is another 2.7.6 installed on cluster publicly. 我在本地安装了python2.7.6,并且在集群上公开安装了另一个2.7.6。

Then I use my local python to install a pip but when I 'pip list', it returns: 然后,我使用本地python安装pip,但是当我“点列表”时,它返回:

$ pip list Traceback (most recent call last): File "/home/zengh/.local/bin/pip", line 7, in from pip import main File "/home/zengh/.local/lib/python2.7/site-packages/pip/ init .py", line 13, in from pip.utils import get_installed_distributions, get_prog File "/home/zengh/.local/lib/python2.7/site-packages/pip/utils/ init .py", line 5, in import locale File "/home/software/rhel6/python/2.7.6/lib/python2.7/locale.py", line 18, in import operator ImportError: /home/software/rhel6/python/2.7.6/lib/python2.7/lib-dynload/operator.so: undefined symbol: _PyUnicodeUCS2_AsDefaultEncodedString $ pip list追溯(最近一次通话最后一次):文件“ /home/zengh/.local/bin/pip”,第7行,从pip导入主文件,文件“ /home/zengh/.local/lib/python2.7/来自pip.utils的site-packages / pip / init .py“,第13行,导入ge​​t_installed_distributions,get_prog文件“ /home/zengh/.local/lib/python2.7/site-packages/pip/utils/ init .py导入语言环境文件“ /home/software/rhel6/python/2.7.6/lib/python2.7/locale.py”中的第5行,导入操作ImportError ImportError中的第18行:/ home / software / rhel6 / python /2.7.6/lib/python2.7/lib-dynload/operator.so:未定义符号:_PyUnicodeUCS2_AsDefaultEncodedString

Obviously it calls the locale.py on the cluster while my PYTHONPATH only contains my local python's path. 显然,它在群集上调用locale.py,而我的PYTHONPATH仅包含本地python的路径。 How can I make it call the 我该如何称呼它

/.local/python2.7.6/lib/python2.7/locale.py? /.local/python2.7.6/lib/python2.7/locale.py?

Thanks 谢谢

Depends on whether you want to set it from within a script or from os. 取决于您是要在脚本中还是在os中进行设置。

From script: 从脚本:

    import sys
    sys.path.append('additional dir')

From os: 从操作系统:

    export PYTHONPATH=somewhere

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM