使用 Python 和 Pip

使用 Python 和 Pip

我正在嘗試配置 Python 和 Python3 供 Linux Jenkins 從屬設備使用。在管理模組方面,有人建議我使用 Pip for Python 和 Pip3 for Python3。我不知道如何,但 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 也找不到模組。

相關內容