安装别的东西后,Python导入顺序错误

时间:2016-02-27 01:54:58

标签: python import path

基本上我从中获取libs /usr/lib/python2.7/dist-packages'(well'/usr/local/lib/python2.7/dist-packages/Theano-0.7.0-py2.7.egg') 之前 '/u/arvie/.local/lib/python2.7/site-packages'

我尝试过使用PYTHONPATH和PYTHONUSERBASE并且没有到达任何地方。这个问题发生在我从git安装了一个包之后(我在它导致这个混乱之后删除了它)。

Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import theano
theano.__fileUsing gpu device 0: GeForce GTX TITAN X
>>> theano.__file__
'/usr/local/lib/python2.7/dist-packages/Theano-0.7.0-py2.7.egg/theano/__init__.pyc'
>>> import sys
>>> sys.path
['', '/usr/local/lib/python2.7/dist-packages/easydict-1.6-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/Theano-0.7.0-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/pysrt-1.0.1-py2.7.egg', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/u/arvie/.local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gst-0.10', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode']
>>> import site
>>> site.getuserbase()
'/u/arvie/.local/'

1 个答案:

答案 0 :(得分:0)

您的python sys路径非常复杂,您可能需要稍微清理一下以获得长期稳定性。但是为了快速解决您的问题,请尝试以下方法:

import sys
sys.path.insert(desired_location, module_name)

位置编号应位于您不希望加载模块的目录之前。