2021 年如何在 Python 2.7 上安装 pip

如何解决2021 年如何在 Python 2.7 上安装 pip

我有仍在运行 Python 2.7.6 的旧生产服务器。我们有一个从 ubuntu 14.04 的 docker 映像构建的本地环境,旨在复制该环境(一旦安装了所有东西,一切仍然可以在那里工作。)由于 PyPi 放弃了非 SNI 支持,创建此环境的打包程序构建脚本最近显然停止工作。

我尝试使用文档中的 get-pip.py 下载 pip:

wget -c https://bootstrap.pypa.io/pip/2.7/get-pip.py
python2 get-pip.py

这给了我以下警告:

DEPRECATION: Python 2.7 reached the end of its life on January 1st,2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
/tmp/tmpBb3LJu/pip.zip/pip/_vendor/urllib3/util/ssl_.py:424: SNIMissingWarning: An HTTPS request has been made,but the SNI (Server 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/advanced-usage.html#ssl-warnings
/tmp/tmpBb3LJu/pip.zip/pip/_vendor/urllib3/util/ssl_.py:164: 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/advanced-usage.html#ssl-warnings
ERROR: Could not find a version that satisfies the requirement pip<21.0 (from versions: none)
ERROR: No matching distribution found for pip<21.0

建议的解决方案是使用 pip 升级 urllib3 https://serverfault.com/questions/866062/easy-install-and-pip-fail-with-ssl-warnings

我没有 pip,所以我使用

安装了旧版本
apt-get install python-pip

这将安装 pip 1.5.4

当我尝试 pip install "urllib3[secure]" 时,我得到以下信息:

Requirement already satisfied (use --upgrade to upgrade): urllib3[secure] in /usr/lib/python2.7/dist-packages
  Installing extra requirements: 'secure'
Cleaning up...

如果我尝试 pip install "urllib3[secure]" --upgradepip install --index-url https://pypi.python.org/simple/ --upgrade pip 我得到:

Cannot fetch index base URL https://pypi.python.org/simple/
Could not find any downloads that satisfy the requirement urllib3[secure] in /usr/lib/python2.7/dist-packages
Downloading/unpacking urllib3[secure]
Cleaning up...
No distributions at all found for urllib3[secure] in /usr/lib/python2.7/dist-packages
Storing debug log for failure in /root/.pip/pip.log

(pip 消息反映的是 pip,而不是 urllib3[secure])

当我尝试使用 pip 1.5 安装 uWSGI

pip install uWSGI

我得到以下信息:

Downloading/unpacking uWSGI
  Cannot fetch index base URL https://pypi.python.org/simple/
  Could not find any downloads that satisfy the requirement uWSGI
Cleaning up...
No distributions at all found for uWSGI
Storing debug log for failure in /root/.pip/pip.log

升级 pip 在这里也不起作用

Downloading/unpacking uWSGI==2.0.18 (from -r /root/requirements.txt (line 1))
  Cannot fetch index base URL https://pypi.python.org/simple/
  Could not find any downloads that satisfy the requirement uWSGI==2.0.18 (from -r /root/requirements.txt (line 1))
Cleaning up...
No distributions at all found for uWSGI==2.0.18 (from -r /root/requirements.txt (line 1))
Storing debug log for failure in /root/.pip/pip.log

重新安装 pip 不起作用:

python -m pip install -U --force-reinstall pip

给我:

Downloading/unpacking pip
  Cannot fetch index base URL https://pypi.python.org/simple/
  Could not find any downloads that satisfy the requirement pip
Cleaning up...
No distributions at all found for pip
Storing debug log for failure in /root/.pip/pip.log

如果我打开 /root/.pip/pip.log,我会看到以下内容:

Downloading/unpacking pip
  Getting page https://pypi.python.org/simple/pip/
  Could not fetch URL https://pypi.python.org/simple/pip/: 403 Client Error: [[[!!! BREAKING CHANGE !!!]]] Support for clients that do not support Server Name Indication is temporarily disabled and will be permanently deprecated soon. See https://status.python.org/incidents/hzmjhqsdjqgb and https://github.com/pypa/pypi-support/issues/978 [[[!!! END BREAKING CHANGE !!!]]]

The link 表示已取消 SNI 支持:

For users of Python 2.7.{0...8}
Upgrading to the last Python 2.7 release is an option.

However,note that Python 2.7 series itself is now End of Life and support in pip was dropped with version 21.0.

For users of Python 2.6.x and lower:
Neither the Python core developers,or pip maintainers support Python 2.6 and below.

If someone is aware of a work around for this issue (SNI support specifically) they are welcome to share it here for others.

There is no recommended solution from the PyPI team.

如何为新开发人员设置本地环境以处理我们的旧应用程序?我已经创建了一个新的 Python 3 开发服务器和本地环境,但是我还需要一段时间才能推出临时环境和实时环境,将所有内容都移过去并进行测试。

解决方法

正如消息所述,截至 2021 年 5 月 6 日,PyPi 具有适用于 Python discontinued support。如果您运行的是 PyPi 手动下载轮子。

这些是我需要对构建脚本进行的修改以使其正常工作:

我需要安装 software-properties-commongcc

apt-get install -y software-properties-common gcc

然后我下载了 (setuptools](https://pypi.org/project/setuptools/44.1.1/#files) 并解压并安装了它:

python ./setuptools-44.1.1/setup.py install

接下来,我下载了 pip 并将其添加到名为 wheels 的文件夹中。然后我可以使用whl文件运行pip来获取pip

python ./wheels/pip-20.3.4-py2.py3-none-any.whl/pip install --no-index --find-links ./wheels/ pip --ignore-installed

建议使用 Ubuntu 16.04 和 Python 2.7.17 构建一个 Docker 容器,并使用它来下载包。

pip download -r requirements.txt

但是软件包的版本是错误的,所以我最终浏览了 requirements.txt 并从 PyPi 手动下载了每个软件包并将其添加到 wheels 文件夹中。正在运行的实例很有用,因此您可以运行 pip freeze 或查看 requirements.txt 文件以获取所需的所有软件包的版本号。

现在我可以使用 pip,我可以安装我的其他软件包了:

python pip install --no-index --find-links ./wheels/ -r /root/requirements.txt

这发现了一些我还没有下载软件包的依赖项,所以我不得不下载这些依赖项并将它们添加到 wheels 文件夹中。我发现还有一些其他东西需要与我最初下载的版本不同,一些软件包依赖于 pbr,还有更多需要 wheel

pip install --no-index --find-links ./wheels/ pbr==5.5.1 wheel==0.36.2

我还需要下载 cMake 并将其添加到 wheels 文件夹

之后我可以安装我的requirements.txt

pip install --no-index --find-links ./wheels/ -r /root/requirements.txt --ignore-installed
,

可能会迟到,但在我尝试使用 Python 2.7.6(缺乏 SNI 支持)发出 HTTPS 请求时发生了类似的事情。这在我工作的远程 Web 服务器上造成了很多问题。

寻找答案我尝试安装 urllib3[secure] 并进入了一个漏洞,因为 pip 抱怨缺乏 SNI 支持来安装这个和其他软件包。

我发现了这个 StackOverflow answer,它帮助我安装了使 Python 2.7.6 和 pip 本身支持 SNI 以及安装 urllib[secure] 所需的依赖项。

您需要创建一个包含所需轮子的文件夹(例如使用 wget 从 PyPi 下载它们):

pip、asn1crypto、enum34、idna、6、ipaddress、pyOpenSSL、cffi、 密码轮;还有 pycparser(一个非轮子,它将是一个 tar.gz)

确保您下载的轮子支持 Python 2.7,并且在其他轮子之前安装 pip。

在原始答案中,它声明您可以使用 python -m OpenSSL.debug 来验证一切正常(ModuleNotFoundError 表示未安装 pyOpenSSL 包)。您还可以使用 pip -V 检查新的 pip 版本是否也已正确安装。

更新 pip 并安装这些依赖项后,我能够安装 urllib3[secure] 并从 python 和 pip 获得 SNI 支持。

祝你好运!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-