-
Notifications
You must be signed in to change notification settings - Fork 419
Expand file tree
/
Copy pathpython.install.html
More file actions
300 lines (238 loc) · 14.3 KB
/
Copy pathpython.install.html
File metadata and controls
300 lines (238 loc) · 14.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>1.2. Python 安装</title><link rel="stylesheet" type="text/css" href="../docbook.css" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><meta name="keywords" content="php,pear,pecl,phar, python, , " /><link rel="home" href="../index.html" title="Netkiller Python 手札" /><link rel="up" href="index.html" title="第 1 章 Python 入门" /><link rel="prev" href="index.html" title="第 1 章 Python 入门" /><link rel="next" href="venv.html" title="1.3. venv - Python 虚拟环境" /></head><body><a xmlns="" href="//www.netkiller.cn/">Home</a> | <a xmlns="" href="//netkiller.github.io/">简体中文</a> | <a xmlns="" href="http://netkiller.sourceforge.net/">繁体中文</a> | <a xmlns="" href="/journal/index.html">杂文</a>
| <a xmlns="" href="https://github.com/netkiller">Github</a> | <a xmlns="" href="https://zhuanlan.zhihu.com/netkiller">知乎专栏</a> | <a xmlns="" href="https://www.facebook.com/bg7nyt">Facebook</a> | <a xmlns="" href="http://cn.linkedin.com/in/netkiller/">Linkedin</a> | <a xmlns="" href="https://www.youtube.com/user/bg7nyt/videos">Youtube</a> | <a xmlns="" href="//www.netkiller.cn/home/donations.html">打赏(Donations)</a> | <a xmlns="" href="//www.netkiller.cn/home/about.html">About</a><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">1.2. Python 安装</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="index.html">上一页</a> </td><th width="60%" align="center">第 1 章 Python 入门</th><td width="20%" align="right"> <a accesskey="n" href="venv.html">下一页</a></td></tr></table><hr /></div><table xmlns=""><tr><td><iframe src="//ghbtns.com/github-btn.html?user=netkiller&repo=netkiller.github.io&type=watch&count=true&size=large" height="30" width="170" frameborder="0" scrolling="0" style="width:170px; height: 30px;" allowTransparency="true"></iframe></td><td><iframe src="//ghbtns.com/github-btn.html?user=netkiller&repo=netkiller.github.io&type=fork&count=true&size=large" height="30" width="170" frameborder="0" scrolling="0" style="width:170px; height: 30px;" allowTransparency="true"></iframe></td><td><iframe src="//ghbtns.com/github-btn.html?user=netkiller&type=follow&count=true&size=large" height="30" width="240" frameborder="0" scrolling="0" style="width:240px; height: 30px;" allowTransparency="true"></iframe></td><td></td><td><a href="https://zhuanlan.zhihu.com/netkiller"><img src="/images/logo/zhihu-card-default.svg" height="25" /></a></td><td valign="middle"><a href="https://zhuanlan.zhihu.com/netkiller">知乎专栏</a></td><td></td><td></td><td></td><td></td></tr></table><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="python.install"></a>1.2. Python 安装</h2></div></div></div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="id779"></a>1.2.1. Rocky Linux / AlmaLinux 安装 Python</h3></div></div></div>
<p>系统默认 python3.9 安装 python3.13</p>
<pre class="screen">
[root@development ~]# dnf search python | grep "^python3.13"
Last metadata expiration check: 0:15:05 ago on Thu 24 Jul 2025 08:43:36 AM CST.
python3.13.x86_64 : Version 3.13 of the Python interpreter
python3.13-debug.x86_64 : Debug version of the Python runtime
python3.13-devel.x86_64 : Libraries and header files needed for Python development
python3.13-freethreading.x86_64 : Free Threading (PEP 703) version of the Python runtime
python3.13-freethreading-debug.x86_64 : Free Threading (PEP 703) version of the Python runtime (debug build)
python3.13-idle.x86_64 : A basic graphical development environment for Python
python3.13-libs.x86_64 : Python runtime libraries
python3.13-packaging.noarch : Core utilities for Python packages
python3.13-pip.noarch : A tool for installing and managing Python packages
python3.13-rpm.x86_64 : Python 3.13 bindings for apps which will manipulate RPM packages
python3.13-setuptools.noarch : Easily build and distribute Python packages
python3.13-test.x86_64 : The self-test suite for the main python3 package
python3.13-tkinter.x86_64 : A GUI toolkit for Python
python3.13-flit-core.noarch : PEP 517 build backend for packages using Flit
python3.13-pip-wheel.noarch : The pip wheel
python3.13-setuptools-wheel.noarch : The setuptools wheel
</pre>
<p></p>
<pre class="screen">
[root@development ~]# dnf install -y python3.13 python3.13-pip
</pre>
<p>切换默认版本</p>
<pre class="screen">
[root@development ~]# ls -l /usr/bin/python{,3}
lrwxrwxrwx 1 root root 9 2025-07-02 08:44 /usr/bin/python -> ./python3
lrwxrwxrwx 1 root root 9 2025-07-02 08:44 /usr/bin/python3 -> python3.9
</pre>
<p>手工修改,创建符号链接,因为 python 指向 python3,所以我门只处理 python3 即可</p>
<pre class="screen">
# 先删除现有链接
sudo rm -f /usr/bin/python3
# 创建指向 Python 3.13 的新链接
sudo ln -s /usr/bin/python3.13 /usr/bin/python3
# 验证版本
python3 --version
</pre>
<p>alternatives 方案</p>
<pre class="screen">
# 查看当前 Python 方案
sudo alternatives --config python3
# 如果没有 Python 3.13 的选项,手动添加
sudo alternatives --install /usr/bin/python3 python3 /usr/bin/python3.13 2
sudo alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1
# 再次配置默认版本
sudo alternatives --config python3
# 然后输入对应 Python 3.13 的编号并回车
</pre>
<p>推荐安装</p>
<pre class="screen">
[root@development ~]# dnf install python3.13-setuptools python3.13-freethreading
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="python.install.docker"></a>1.2.2. Docker 安装</h3></div></div></div>
<pre class="screen">
$ docker run --name python --rm -it python
Python 3.10.1 (main, Dec 21 2021, 09:01:08) [GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
</pre>
<p>Dockerfile 制作自己的镜像</p>
<pre class="screen">
FROM python:latest
MAINTAINER Netkiller <netkiller@msn.com>
RUN pip install pymysql sqlalchemy openpyxl pandas -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN mkdir /data
ADD export.py /srv
VOLUME ["/tmp"]
WORKDIR /data
#EXPOSE 80 443
ENTRYPOINT python3 /srv/export.py
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="python3.dnf"></a>1.2.3. dnf 安装 python3.11</h3></div></div></div>
<p>安装 Python 3.11 适用鱼 Rocky Linux 9.2 和 AlmaLinux 9.2</p>
<pre class="screen">
dnf install -y python3.11 python3.11-pip
</pre>
<p>系统默认是 python3.9,将其切换到 python3.11</p>
<pre class="screen">
update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 2
</pre>
<p>切换 pip 到 3.11</p>
<pre class="screen">
[root@iZwz9cug5b7jbx1dc4nwniZ ~]# mv /usr/bin/pip{,.backup}
[root@iZwz9cug5b7jbx1dc4nwniZ ~]# mv /usr/bin/pip3{,.backup}
[root@iZwz9cug5b7jbx1dc4nwniZ ~]# alternatives --install /usr/bin/pip pip /usr/bin/pip3.11 1
[root@iZwz9cug5b7jbx1dc4nwniZ ~]# alternatives --install /usr/bin/pip3 pip3 /usr/bin/pip3.11 2
[root@iZwz9cug5b7jbx1dc4nwniZ ~]# pip -V
pip 22.3.1 from /usr/lib/python3.11/site-packages/pip (python 3.11)
</pre>
<p>检查 python 是否工作正常</p>
<pre class="screen">
[root@iZwz9cug5b7jbx1dc4nwniZ srv]# alternatives --list
libnssckbi.so.x86_64 auto /usr/lib64/pkcs11/p11-kit-trust.so
soelim auto /usr/bin/soelim.groff
cifs-idmap-plugin auto /usr/lib64/cifs-utils/cifs_idmap_sss.so
iptables auto /usr/sbin/iptables-nft
ebtables auto /usr/sbin/ebtables-nft
arptables auto /usr/sbin/arptables-nft
ld auto /usr/bin/ld.bfd
man auto /usr/bin/man.man-db
nc auto /usr/bin/ncat
man.7.gz auto /usr/share/man/man7/man.man-pages.7.gz
libwbclient.so.0.15-64 auto /usr/lib64/samba/wbclient/libwbclient.so.0.15
python auto /usr/bin/python3.11
[root@iZwz9cug5b7jbx1dc4nwniZ srv]# alternatives --display python
python - status is auto.
link currently points to /usr/bin/python3.11
/usr/bin/python3.11 - priority 1
Current `best' version is /usr/bin/python3.11.
[root@iZwz9cug5b7jbx1dc4nwniZ srv]# python
Python 3.11.2 (main, May 24 2023, 00:00:00) [GCC 11.3.1 20221121 (Red Hat 11.3.1-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="id780"></a>1.2.4. 编译安装 Python3.x</h3></div></div></div>
<pre class="screen">
./configure --prefix=/usr/local/python-3.1.2
make && make install
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="id781"></a>1.2.5. Ubunut 13.04 环境安装python3</h3></div></div></div>
<pre class="screen">
$ sudo apt-get install python3
</pre>
<p>python 3.3</p>
<pre class="screen">
$ sudo apt-get install python3.3
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="pypy"></a>1.2.6. pypy - fast alternative implementation of Python - PyPy
interpreter
</h3></div></div></div>
<p>http://pypy.org/</p>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="id782"></a>1.2.6.1. Ubuntu 环境安装</h4></div></div></div>
<pre class="screen">
$ apt-cache search pypy | grep pypy
pypy - fast alternative implementation of Python - PyPy interpreter
pypy-dev - header files for PyPy (an alternative Python interpreter)
pypy-doc - developer Documentation for PyPy (an alternative Python interpreter)
pypy-lib - standard library for PyPy (an alternative Python interpreter)
python-pypy.translator.sandbox - sandboxed PyPy interpreter
</pre>
<pre class="screen">
$ sudo apt-get install pypy
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="id783"></a>1.2.6.2. CentOS 环境安装</h4></div></div></div>
<pre class="screen">
# yum install pypy
</pre>
</div>
</div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="eric"></a>1.2.7. Eric Python IDE</h3></div></div></div>
<pre class="screen">
apt-get install eric
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="exe"></a>1.2.8. python to exe</h3></div></div></div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="pyinstaller"></a>1.2.8.1. pyinstaller</h4></div></div></div>
<p>http://www.pyinstaller.org/</p>
<div class="section"><div class="titlepage"><div><div><h5 class="title"><a id="id784"></a>Linux</h5></div></div></div>
<p>安装</p>
<pre class="screen">
pip install pyinstaller
</pre>
<p>制作EXE文件</p>
<pre class="screen">
$ pyinstaller test.py
</pre>
<p>dist目录下会生成可执行文件</p>
</div>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="py2exe"></a>1.2.8.2. py2exe</h4></div></div></div>
<p>http://www.py2exe.org/</p>
<p>此软件 2008-11-16 后不再更新</p>
</div>
</div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="python2"></a>1.2.9. Python2.x</h3></div></div></div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="id785"></a>1.2.9.1. 编译安装</h4></div></div></div>
<p>Python2.x</p>
<pre class="screen">
wget http://www.python.org/ftp/python/2.x.x/Python-2.x.x.tgz
tar zxvf Python-2.x.x.tgz
cd Python-2.x.x
./configure --prefix=/usr/local/python2.x
make
make install
ln -s /usr/local/python/bin/python2.5 /usr/bin/
ln -s /usr/local/python/bin/* /usr/local/bin/
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="id786"></a>1.2.9.2. Ubuntu 安装</h4></div></div></div>
<pre class="screen">
sudo apt-get install python
sudo apt-get install python-setuptools
</pre>
</div>
</div>
</div><script xmlns="" type="text/javascript" id="clustrmaps" src="//cdn.clustrmaps.com/map_v2.js?u=r5HG&d=9mi5r_kkDC8uxG8HuY3p4-2qgeeVypAK9vMD-2P6BYM"></script><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="index.html">上一页</a> </td><td width="20%" align="center"><a accesskey="u" href="index.html">上一级</a></td><td width="40%" align="right"> <a accesskey="n" href="venv.html">下一页</a></td></tr><tr><td width="40%" align="left" valign="top">第 1 章 Python 入门 </td><td width="20%" align="center"><a accesskey="h" href="../index.html">起始页</a></td><td width="40%" align="right" valign="top"> 1.3. venv - Python 虚拟环境</td></tr></table></div><script xmlns="">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-11694057-1', 'auto');
ga('send', 'pageview');
</script><script xmlns="" async="async">
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?93967759a51cda79e49bf4e34d0b0f2c";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script><script xmlns="" async="async">
(function(){
var bp = document.createElement('script');
var curProtocol = window.location.protocol.split(':')[0];
if (curProtocol === 'https') {
bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
}
else {
bp.src = 'http://push.zhanzhang.baidu.com/push.js';
}
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(bp, s);
})();
</script></body></html>