使用 Python 和 Pip

使用 Python 和 Pip

我正在尝试配置 Python 和 Python3 以供 Linux Jenkins 从属使用。有人建议我在管理模块方面对 Python 使用 Pip,对 Python3 使用 Pip3。我不确定怎么做,但 Pip 和 Pip3 都指向我的 Python 3.6 安装。这可能是一个转移注意力的借口,但我试图导入模块“SlackClient”,并被告知找不到该模块,尽管它还说它已经安装。有关更多详细信息,请参阅下文:

$ python py.py
Traceback (most recent call last):
  File "py.py", line 1, in <module>
    import SlackClient
ImportError: No module named SlackClient

$ python3 py.py
Traceback (most recent call last):
  File "py.py", line 1, in <module>
    import SlackClient
ModuleNotFoundError: No module named 'SlackClient'

每当我尝试安装模块时:

$ pip install slackclient
Requirement already satisfied: slackclient in /usr/local/lib64/python3.6/site-packages (2.0.1)
Requirement already satisfied: aiohttp>3.5.2 in /usr/local/lib64/python3.6/site-packages (from slackclient) (3.5.4)
Requirement already satisfied: aiodns>1.0 in /usr/local/lib/python3.6/site-packages (from slackclient) (2.0.0)
Requirement already satisfied: async-timeout<4.0,>=3.0 in /usr/local/lib/python3.6/site-packages (from aiohttp>3.5.2->slackclient) (3.0.1)
Requirement already satisfied: idna-ssl>=1.0; python_version < "3.7" in /usr/local/lib/python3.6/site-packages (from aiohttp>3.5.2->slackclient) (1.1.0)
Requirement already satisfied: multidict<5.0,>=4.0 in /usr/local/lib64/python3.6/site-packages (from aiohttp>3.5.2->slackclient) (4.5.2)
Requirement already satisfied: typing-extensions>=3.6.5; python_version < "3.7" in /usr/local/lib/python3.6/site-packages (from aiohttp>3.5.2->slackclient) (3.7.4)
Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib64/python3.6/site-packages (from aiohttp>3.5.2->slackclient) (1.3.0)
Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.6/site-packages (from aiohttp>3.5.2->slackclient) (19.1.0)
Requirement already satisfied: chardet<4.0,>=2.0 in /usr/local/lib/python3.6/site-packages (from aiohttp>3.5.2->slackclient) (3.0.4)
Requirement already satisfied: pycares>=3.0.0 in /usr/local/lib64/python3.6/site-packages (from aiodns>1.0->slackclient) (3.0.0)
Requirement already satisfied: typing; python_version < "3.7" in /usr/local/lib/python3.6/site-packages (from aiodns>1.0->slackclient) (3.7.4)
Requirement already satisfied: idna>=2.0 in /usr/local/lib/python3.6/site-packages (from idna-ssl>=1.0; python_version < "3.7"->aiohttp>3.5.2->slackclient) (2.8)
Requirement already satisfied: cffi>=1.5.0 in /usr/local/lib64/python3.6/site-packages (from pycares>=3.0.0->aiodns>1.0->slackclient) (1.12.3)
Requirement already satisfied: pycparser in /usr/local/lib/python3.6/site-packages (from cffi>=1.5.0->pycares>=3.0.0->aiodns>1.0->slackclient) (2.19)

我的环境设置如下:

$ python --version
    Python 2.7.14
$ python3 --version
    Python 3.6.8
$ pip --version
    pip 19.1.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
$ pip3 --version
    pip 19.1.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)

$ which pip
    /usr/local/bin/pip
$ which pip3
    /usr/local/bin/pip3
$ which python
    /usr/bin/python
$ which python3
    /usr/bin/python3

Python 看不到模块似乎很奇怪。我唯一能想到的是,两个 Pips 似乎都在将包安装到 Python 3.6,但我不明白为什么 Python3 也找不到模块。

相关内容