【问题标题】:How to install 2 python versions on ubuntu 18.04? (Without using virtual environment)如何在 ubuntu 18.04 上安装 2 个 python 版本? (不使用虚拟环境)
【发布时间】:2019-08-02 21:37:04
【问题描述】:

我正在尝试安装 2 个 python 版本:

1) 2.7.14

2) 3.7.2-1

我使用 make 命令创建了它们:

wget https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz

tar -xvf Python-2.7.14.tgz

cd Python-2.7.14

./configure --without-ensurepip --enable-optimizations

制作

checkinstall -y

当我解压其中一个时,它会覆盖安装的第二个:

dpkg -i python_2.7.14-1_amd64.deb

dpkg:警告:将 python 从 3.7.2-1 降级到 2.7.14-1

(正在读取数据库...当前 35940 个文件和目录 已安装。)

准备解压python_2.7.14-1_amd64.deb ...

在 (3.7.2-1) 之上解压 python (2.7.14-1) ...

设置 python (2.7.14-1) ...

如何让它们都在我的 ubuntu 上运行?

**** 注意我不想使用虚拟环境 ****

【问题讨论】:

标签: python ubuntu dpkg


【解决方案1】:

Python 已经安装在你的机器上...如果你要运行不同的版本,你最好配置一个虚拟环境

【讨论】:

  • 但据我所知,Ubuntu 可以有 2 个版本。我有一台运行 2.7 和 3.5 的机器,没有虚拟环境。
  • 是的,您可以拥有一个 python3 版本和一个 python 2 版本。在 Ubuntu 18 上,默认情况下不安装 python 2。请查看linuxconfig.org/…
  • 你试过sudo apt install python-minimal吗?有了这个我已经安装了Python 2.7.15,但你想要2.7.14,对吧?
  • 顺便说一句,我不建议您安装默认版本以外的其他 python 版本。 Ubuntu 18 带有特定版本的 python 3,整个系统都有这种“依赖”。使用虚拟环境改变故事
【解决方案2】:

首先,卸载任何高于 2.7 的软件包。

选项 1:

您可以使用源代码 python 和“make altinstall”

文档:https://docs.python.org/3/using/unix.html#building-python

选项 2:

使用 apt-get 我可以安装/更新版本 2.7.15 和 3.7.1-1 使用 docker 环境和这个 Dockerfile:

FROM ubuntu:18.04

USER root

WORKDIR /app

RUN apt-get update && apt-get install python=2.7.15~rc1-1 python3.7=3.7.1-1~18.04 -y

这意味着,如果您使用此代码:

apt-get update && apt-get install python python3.7 -y

它可能会起作用。

【讨论】:

  • 没有帮助,尝试安装:make、make altinstall、checkinstall -y 和 Python3 覆盖了 Python2
  • make install 只是更改可执行文件,如果 python3 和 make install 你应该使用“python3”作为可执行文件,而 python 2 将只是“python”。 3.6.2 等次要版本的进一步安装将是“Python3.6”及更高版本。
  • 在 Ubuntu 中,通常已经安装了 2.7,并且您应该从源代码而不是 deb 包安装任何其他版本(如果您希望两者都工作)。我的最后一个猜测是,你应该制作一个完整的,然后从源代码安装下一个,而不是使用 .deb 包。我将使用 Dockerfile 进行测试,以检查这种情况是否可行。
猜你喜欢
  • 2019-12-24
  • 1970-01-01
  • 1970-01-01
  • 2018-12-05
  • 2021-04-11
  • 1970-01-01
  • 1970-01-01
  • 2021-10-20
  • 1970-01-01
相关资源
最近更新 更多