我使用的是 Debian GNU/Linux 7.11(喘息),默认的 python 是 2.7.3,pip 是 1.1(我已经更新到 9.x)。我安装了 python 3.6 来运行一些脚本,弹出此错误,
Traceback (most recent call last):
File "place_fixed2_debugged.py", line 2, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
所以我尝试了pip install requests
,它显示它已经安装,然后我尝试手动安装请求模块,我下载了 requests-2.18.4 并运行python3 setup.py
,出现此错误,
File "setup.py", line 9, in <module>
from setuptools import setup
ModuleNotFoundError: No module named 'setuptools'
然后我尝试apt-get install python3-setuptools
显示也已安装 python3-setuptools 也已安装。
我认为这里的问题是,pip和apt正在将所有python相关的包安装在链接到默认python2.7的路径下,requests模块和setuptool都没有链接到python3。
我尝试了 virtualenv,它需要 zlib 模块,pip install zlib
给出
root@localhost:~/Python-3.6.0# pip install zlib
Collecting zlib
/usr/local/lib/python2.7/dist-packages/pip-9.0.1-py2.7.egg/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
SNIMissingWarning
/usr/local/lib/python2.7/dist-packages/pip-9.0.1-py2.7.egg/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Could not find a version that satisfies the requirement zlib (from versions: )
No matching distribution found for zlib
还有其他更易于管理的方法让我将 pip 链接到 python3.6 吗?我真的不想设置 virtualenv,谢谢!
答案1
你需要跑sudo apt install pip3