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 버전입니다.

관련 정보