Python2安装setuptools/pip/pyinstaller

本文详细介绍如何在Python2.7.6环境下安装setuptools、pip及pyinstaller等工具,并提供了具体的安装步骤与命令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

0x00 前言

本文撰写时python2版本已定格在2.7.x,仅作有需要旧依赖的兼容性使用。

本文基于python2经典版本2.7.6。https://www.python.org/downloads/release/python-276/

0x01 setuptools安装

pip依赖于setuptools,首先解决。

方式①:一键安装脚本

# 下载ez_setup.py,wget或者windows迅雷下单都可
wget https://bootstrap.pypa.io/ez_setup.py

# 这里的python命令可以替换为绝对路径,因为是旧项目用得不多,懒得设置环境变量
# python ez_setup.py
C:\Python27\python.exe ez_setup.py

方式②:源码安装

# python2对应setuptools要选旧版本,此处推荐36.5.0
https://pypi.org/project/setuptools/36.5.0

# 同样任意方式下载
wget https://files.pythonhosted.org/packages/a4/c8/9a7a47f683d54d83f648d37c3e180317f80dc126a304c45dc6663246233a/setuptools-36.5.0.zip

# 安装,一定要cd进去,否则会出现路径错误
cd setuptools-36.5.0
python setup.py install

0x02 pip安装

方式①:源码安装

pip兼容性不错,选择最新版也能兼容旧版本python2,下载最新版即可。

https://pypi.org/project/pip/#files

# 解压后一定要cd进去,否则会出现路径错误
cd pip

python setup.py install

# 至此可以使用命令,但不正常
python -m pip install wheel

# 在报错堆栈里misc.py 710行把url固定为清华源即可
# 原因是netloc有bug,把url自动加了前缀"https://"
misc.py:710  url="https://pypi.tuna.tsinghua.edu.cn/simple"

方式②:一键脚本安装

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

0x03 pyinstaller安装

# pyinstaller下载安装
pyinstaller v2.1是python2受支持的最后一个版本。https://github.com/pyinstaller/pyinstaller/releases/tag/v2.1

# 安装pyinstaller本体
cd PyInstaller-2.1
python2 setup.py install

# Windows下安装pywin32依赖包
python2 -m pip install pywin32

# distribute依赖包下载安装
https://pypi.org/project/distribute/0.6.49
cd distribute-0.6.49
python2 setup.py install

# 测试
Python27(python2根目录)\Scripts\pyinstaller.exe -F test.py

 

[root@0404 ~]# pip3 install pyinstaller WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead. Collecting pyinstaller Using cached https://files.pythonhosted.org/packages/b0/e6/e5760666896739115b0e4538a42cdd895215581618ec885ad043dd35ee57/pyinstaller-4.10.tar.gz Requirement already satisfied: setuptools in /usr/lib/python3.6/site-packages (from pyinstaller) Requirement already satisfied: altgraph in ./.local/lib/python3.6/site-packages (from pyinstaller) Requirement already satisfied: pyinstaller-hooks-contrib>=2020.6 in ./.local/lib/python3.6/site-packages (from pyinstaller) Requirement already satisfied: importlib-metadata in ./.local/lib/python3.6/site-packages (from pyinstaller) Requirement already satisfied: zipp>=0.5 in ./.local/lib/python3.6/site-packages (from importlib-metadata->pyinstaller) Requirement already satisfied: typing-extensions>=3.6.4; python_version < "3.8" in ./.local/lib/python3.6/site-packages (from importlib-metadata->pyinstaller) Building wheels for collected packages: pyinstaller Running setup.py bdist_wheel for pyinstaller ... error Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-9i8u5dao/pyinstaller/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpmvsymh1kpip-wheel- --python-tag cp36: running bdist_wheel running build running build_bootloader No precompiled bootloader found or compile forced. Trying to compile the bootloader for you ... Setting top to : /tmp/pip-build-9i8u5dao/pyinstaller/bootloader Setting out to : /tmp/pip-build-9i8u5dao/pyinstaller/bootloader/build Python Version : 3.6.8 (default, Nov 14 2023, 16:29:52) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] Checking for 'gcc' (C compiler) : /usr/bin
03-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值