未找到 Python 模块路径

未找到 Python 模块路径

在我们的 Openstack 安装中出现了严重错误。现在 Python 不再正常工作。找不到模块路径:

root@controller:/root# keystone token-get
Traceback (most recent call last):
  File "/usr/bin/keystone", line 6, in <module>
    from keystoneclient.shell import main
ImportError: No module named shell

如果我通过环境变量添加模块路径,这个错误就会消失......(其他错误目前并不重要)

root@controller:/root# export PYTHONPATH=/usr/lib/python2.7/dist-packages
root@controller:/root# keystone token-get
Authorization Failed: Unable to establish connection to http://controller:35357/v2.0/tokens

奇怪的细节:即使没有设置环境变量,python -m site 似乎也知道正确的路径:

sys.path = [
'/root',
'/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',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
]
USER_BASE: '/root/.local' (doesn't exist)
USER_SITE: '/root/.local/lib/python2.7/site-packages' (doesn't exist)
ENABLE_USER_SITE: True

由于 Python 在 Apache 中也不适用于仪表板,因此每次都使用“export”设置环境变量不是一个选择。我们需要在其他地方修复该问题。

python包含路径在哪里配置?

更新:

lib 路径的顺序似乎很重要。这是有效的:

PYTHONPATH=/usr/lib/python2.7/dist-packages:/usr/local/lib/python2.7/dist-packages; keystone token-get

但这是行不通的:

PYTHONPATH=/usr/local/lib/python2.7/dist-packages:/usr/lib/python2.7/dist-packages; keystone token-get

答案1

export PYTHONPATH=/usr/lib/python2.7/dist-packages:/usr/local/lib/python2.7/dist-packages; keystone token-get

对我有用,谢谢

相关内容