1

我正在研究在我们的项目中升级到 Python 3.6 的可能性。

现在我们ppa:fkrull/deadsnakes在 Ubuntu 14.04 上使用 Python 3.5.2。PPA 还没有 Python 3.6,它何时可用尚不清楚。

我不想再安装另一个 PPA。

我正在尝试找到一种更通用的方法。

我发现有人建议使用pyenvwhich 从源代码编译 Python,这听起来很有趣,因为我可以随时升级 Python,而无需等到 repo 维护者添加它。我还可以轻松安装其他 Python 风格,例如 PyPy。

我还没有准备好使用 pyenv 作为虚拟环境,是的,所以我想知道是否可以使用它来全局编译和安装 Python,以便我可以使用它。

4

4 回答 4

8

文档有点混乱,因为安装后没有python-build添加二进制文件PATH

python-build是一个pyenv插件(默认安装)。文档和更多信息在这里:https ://github.com/pyenv/pyenv/tree/master/plugins/python-build 。

How to install system-wide Python for all users: 1) Login as root and 2) install required Python version to /usr/local/python-X.Y.Z.

sudo ~/.pyenv/plugins/python-build/bin/python-build 3.6.1 /usr/local/python-3.6.1/

Now you can use this Python version as a normal user, for example you can create virtualenv for your project:

/usr/local/python-3.6.1/bin/python -m venv /var/www/my-app/.env/
于 2017-04-10T10:59:20.700 回答
1

https://github.com/yyuu/pyenv/wiki/Common-build-problems#installing-a-system-wide-python

安装系统范围的 Python

如果要安装可供所有用户和系统脚本使用的 Python 解释器(无 pyenv),请使用/usr/local/作为安装路径。例如:

sudo python-build 3.3.2 /usr/local/
于 2017-01-02T09:16:34.657 回答
1

我在 deadsnakes 中为可信赖 / xenial 贡献了一个 python3.6 包:)

https://launchpad.net/~fkrull/+archive/ubuntu/deadsnakes/+packages?field.name_filter=python3.6&field.status_filter=published&field.series_filter=

于 2017-01-15T01:04:01.503 回答
0

By combining the hints from the other answers and reading through the documentation, I found a nice way to do exactly what you want that should work well in a CI system or in a Docker container or on a developer machine if they haven't already installed python3.x via Apt or Yum or Homebrew.

Assuming you have all the dependencies required to build your desired version of Python 3.x (anything above 3.4 requires some extra packages the pyenv-installer doesn't always warn you about), you can run the commands below to get a new system wide Python that should be executable by all users, which makes it easy to pass to virtualenv creations with python3.6 -m venv yourvenv.

curl https://pyenv.run | bash # or
wget -O - https://pyenv.run | bash

export PATH="$HOME/.pyenv/bin:$PATH"
$(pyenv which python-build) 3.6.10 /usr/local/

which python3.6
python3.6 --version
# If you get an error running the above commands, it probably means
# /usr/local/bin isn't in your PATH yet
# on Debian/Ubuntu and maybe others the /etc/environment or 
# /etc/login.defs file puts it in the path when a user logs in
echo $PATH
export PATH="/usr/local/bin:$PATH"
python3.6 --version
于 2020-06-08T18:33:39.613 回答