LinuxでPython、pip、およびインストールされたモジュールの場所を識別する方法は?

LinuxでPython、pip、およびインストールされたモジュールの場所を識別する方法は?

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)を使用するように強制するには、installモジュールを使用しますpythonx.x -m pip install <module name>。ここで xx は希望の Python バージョンです。

おすすめ記事