python模块以交互方式正确导入,但在packag中调用时不正确

2024-06-14 07:36:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图让亚马逊冰川工具在Debian上运行(Wheezy,不完全是——我在运行OpenMediaVault)。我已经安装了Python2.6、2.7和3.2。在

glacier命令需要“pytz”包,所以我不得不使用-pip-:

root@srvr:/# pip install pytz
Collecting pytz
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading pytz-2015.4-py2.py3-none-any.whl (475kB)
    100% |████████████████████████████████| 475kB 469kB/s 
Installing collected packages: pytz
Successfully installed pytz-2015.4

好吧,看来成功了。所以,我运行了-glacier cmd而没有任何参数:

^{pr2}$

真的吗?好像安装了。。。让我们用pip2.7再试一次:

root@srvr:/# pip2.7 install pytz
Requirement already satisfied (use --upgrade to upgrade): pytz in /usr/local/lib/python2.7/dist-packages
root@srvr:/# pip2.7 install pytz --upgrade
Requirement already up-to-date: pytz in /usr/local/lib/python2.7/dist-packages
root@srvr:/# which pip
/usr/local/bin/pip
root@srvr:/# which pip2.7
/usr/local/bin/pip2.7

好吧,最后两个命令是多余的,但我变得多疑了。我又试了一次:

在根@srvr:/#冰川命令 回溯(最近一次呼叫): 文件“/usr/local/bin/glacier cmd”,第5行,输入 从包资源导入加载入口点 文件“/usr/lib/python2.7/dist-packages/pkg_资源.py“,第2707行,英寸 工作_设置要求(需要) 文件“/usr/lib/python2.7/dist-packages/pkg_资源.py“,第686行,在require中 需要=自我决定(解析需求(需求)) 文件“/usr/lib/python2.7/dist-packages/pkg_资源.py“,第584行,正在解决 未找到提升分配(req) 包装_未找到resources.DistributionNotFound:pytz公司

我被难住了。我以交互方式运行python和-pytz-imports,似乎运行得很好!在

root@srvr:/# python
Python 2.7.3 (default, Mar 13 2014, 11:03:55) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
- import sys
- print sys.path
['', '/usr/local/lib/python2.7/dist-packages/glacier-0.2dev-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/prettytable-0.7.2-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/boto-2.38.0-py2.7.egg', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/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/PIL', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7']
-  import pytz
-  from pytz import timezone
-  utc=pytz.utc
-  utc.zone
'UTC'
-  exit()

。。。但当我这么称呼它时,它继续失败:

^{pr2}$

我一直以同一用户的身份运行。我甚至放弃了,像根一样不停地跑。在


Tags: installpip文件py命令libpackagesusr
1条回答
网友
1楼 · 发布于 2024-06-14 07:36:12

您的计算机上有两个不同的Python安装:

  /usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.

^{pr2}$

以及

  /usr/local/bin/glacier-cmd

  /usr/lib/python2.7/

使用您的发行版提供的pip包而不是/usr/local/bin/pip来安装pytz,然后{}应该会看到它。或者,如果您计划将pytz与安装到系统范围Python的命令一起使用,则最好从分发包中安装pytz。在

或者构建virtualenv,在这里安装命令和包(推荐)。See Python package installation documentation。在

相关问题 更多 >