![如何在 Linux 上识别 python、pip 和安装的模块位置?](https://linux22.com/image/13939/%E5%A6%82%E4%BD%95%E5%9C%A8%20Linux%20%E4%B8%8A%E8%AF%86%E5%88%AB%20python%E3%80%81pip%20%E5%92%8C%E5%AE%89%E8%A3%85%E7%9A%84%E6%A8%A1%E5%9D%97%E4%BD%8D%E7%BD%AE%EF%BC%9F.png)
我开始学习Python,但发现在Linux上很难理解。
uname -a
Linux machine-name 4.4.0-31-generic #50~14.04.1-Ubuntu SMP Wed Jul 13 01:07:32 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
which python
/usr/local/bin/python
which pip
/usr/local/bin/pip
pip --version
/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/primitives/constant_time.py:26: CryptographyDeprecationWarning: Support for your Python version is deprecated. The next version of cryptography will remove support. Please upgrade to a release (2.7.7+) that supports hmac.compare_digest as soon as possible.
utils.PersistentlyDeprecated2018,
pip 18.1 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)
python
Python 2.7.16 (default, May 6 2020, 13:05:58)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import urllib2
>>> os.path.abspath(urllib2.__file__)
'/usr/local/lib/python2.7/urllib2.pyc'
pip install requests
/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/primitives/constant_time.py:26: CryptographyDeprecationWarning: Support for your Python version is deprecated. The next version of cryptography will remove support. Please upgrade to a release (2.7.7+) that supports hmac.compare_digest as soon as possible.
utils.PersistentlyDeprecated2018,
Requirement already satisfied: requests in ./dist-packages (2.22.0)
Requirement already satisfied: idna<2.9,>=2.5 in ./dist-packages (from requests) (2.8)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in ./dist-packages (from requests) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in ./dist-packages (from requests) (2020.4.5.1)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in ./dist-packages (from requests) (1.25.9)
Python 2.7.16 (default, May 6 2020, 13:05:58)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named requests
>>>
pip install requests
,表示已安装。但是当在交互模式下检查时,由于没有模块名称请求而出错。您能否帮助我了解这些模块正在哪些位置使用(此路径已在何处设置?)以及如何在该特定位置安装模块?
你能帮我么 ?
答案1
我假设您的 pip 版本没有安装适用于您的 python 版本的软件包。 (如 pip3 和 python 2.7)。如果您想强制 pip 使用 python3(或 python 2.7),请使用 安装模块pythonx.x -m pip install <module name>
,其中 xx 是您所需的 python 版本