Python 在大多数 Linux 分发都有预装,且如所有其它包是可用的。不管怎样,可能想要使用的某些特性在您的发行包中是不可用的。可以从源代码轻松编译最新版本的 Python。
若 Python 未预装且也不在存储库中,可以轻松制作您自己的分发包。查看下列链接:
另请参阅
FreeBSD 用户,要添加包使用:
pkg_add -r python
OpenBSD users use:
pkg_add ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/<insert your architecture here>/python-<version>.tgz
例如 i386 用户获取 2.5.1 版的 Python 使用:
pkg_add ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/i386/python-2.5.1p2.tgz
可以获取 Python 从
OpenCSW
。有各种可用 Python 版本,且可以安装如采用
pkgutil -i python27
.
若想自己编译 CPython,首先应该做的事情是获取 source 。可以下载最新发行的源代码,或仅仅直接抓取新鲜 clone (若想要贡献补丁,将需要克隆)。
The build process consists in the usual
./configure make make install
invocations. Configuration options and caveats for specific Unix platforms are extensively documented in the README 文件位于 Python 源代码树根下。
警告
make install
可以覆写或伪装
python3
二进制。
make altinstall
因此推荐代替
make install
由于它仅安装
exec_prefix/bin/pythonversion
.
这可能因本地安装约定而异;
prefix
(
${prefix}
) 和
exec_prefix
(
${exec_prefix}
) 从属安装且应该被解释成 GNU 软件;他们可能相同。
例如,在大多数 Linux 系统,两者默认为
/usr
.
| 文件/目录 | 含义 |
|---|---|
exec_prefix/bin/python3
|
推荐的解释器位置。 |
prefix/lib/pythonversion
,
exec_prefix/lib/pythonversion
|
Recommended locations of the directories containing the standard modules. |
prefix/include/pythonversion
,
exec_prefix/include/pythonversion
|
Recommended locations of the directories containing the include files needed for developing Python extensions and embedding the interpreter. |
要在 Unix 轻松使用 Python 脚本,需要使它们可执行,如采用
$ chmod +x script
并在脚本顶部放置适当 Shebang 行。好的选择通常是
#!/usr/bin/env python3
搜索 Python 解释器在整个
PATH
。不管怎样,某些 UNICE 可能没有
env
命令,所以可能需要硬编码
/usr/bin/python3
作为解释器路径。
要在 Python 脚本中使用 Shell 命令,查看
subprocess
模块。
Vim and Emacs are excellent editors which support Python very well. For more information on how to code in Python in these editors, look at:
Geany is an excellent IDE with support for a lot of languages. For more information, read: https://www.geany.org/
Komodo edit is another extremely good IDE. It also has support for a lot of languages. For more information, read https://komodoide.com/ .