简体   繁体   English

在 Centos 7 中并排安装 Python 版本 3 和版本 2

[英]Install Python version 3 side by side with version 2 in Centos 7

I have a CentOS 7 machine which already has Python 2.7.5 installed.我有一台已经安装了 Python 2.7.5 的 CentOS 7 机器。 Now i want to install Python version 3 also side by side without disturbing the original Python version 2. If i install with pip i fear that it would install version 3 on top of the already existing version.现在我想同时安装 Python 版本 3,而不会干扰原始的 Python 版本 2。如果我使用 pip 安装,我担心它会在现有版本的基础上安装版本 3。

Can someone please guide me how to do the same ?有人可以指导我如何做同样的事情吗? Also i have created a virtualenvs directory inside my installation where i want to create the virualenvs.此外,我在我的安装中创建了一个 virtualenvs 目录,我想在其中创建 virualenvs。

At present whenever i create any virtualenvs using the virtualenv command it automatically copies the Python version 2 installable over there.目前,每当我使用 virtualenv 命令创建任何 virtualenv 时,它都会自动复制可安装的 Python 版本 2。

I want my virtualenvs to contain version 3 and anything outside my virtualenvs should run with version 2.我希望我的 virtualenvs 包含版本 3,并且我的 virtualenvs 之外的任何东西都应该使用版本 2 运行。

Is this even possible.这甚至可能吗。

Thanks a lot for any answers.非常感谢您提供任何答案。

For CentOS 7, we can use IUS Community repo对于 CentOS 7,我们可以使用 IUS Community repo

yum -y install https://centos7.iuscommunity.org/ius-release.rpm
yum -y install python36u
yum -y install python36u-pip
pip3.6 install numpy

So outside your virtualenv, default pip may install for python 2 not python 3.因此,在您的 virtualenv 之外,可能会为 python 2 而不是 python 3 安装默认的 pip。

For Python2 virtaulenv support python3, you can try:对于 Python2 virtaulenv 支持 python3,您可以尝试:

virtualenv python2-bridge
source ./python2-bridge/bin/active
pip install --upgrade virtualenv
virtualenv -p python3 <folder>
source ./<folder>/bin/activate
python --version && pip --version
Python 3.4.3
pip 8.1.2 from /home/centos/<folder>/lib/python3.4/site-packages (python 3.4) 

Refer( https://opsech.io/posts/2016/Sep/06/creating-python-3-virtual-environments-on-centos-7.html )参考( https://opsech.io/posts/2016/Sep/06/creating-python-3-virtual-environments-on-centos-7.html

The simplest method I know is to add the IUS Community repo for Centos 7 (only the most common x86_64 architecture is supported).我知道的最简单的方法是为 Centos 7 添加 IUS Community repo(仅支持最常见的 x86_64 架构)。 Then simply install the required Python3 version directly with yum , eg yum install python36u然后直接用yum安装所需的 Python3 版本,例如yum install python36u

Link: https://ius.io/setup链接: https : //ius.io/setup

Installing anything from an unknown source is a risk.从未知来源安装任何东西都是有风险的。 The IUS has a good reputation - see eg https://wiki.centos.org/AdditionalResources/Repositories - but you must decide yourself if you want to use it. IUS 享有良好的声誉——例如参见https://wiki.centos.org/AdditionalResources/Repositories——但是你必须自己决定是否要使用它。

In case someone stumbles upon this old thread: note that as of CentOS 7.7, python3 is included in the official repos, so you can just do如果有人偶然发现这个旧线程:请注意,从 CentOS 7.7 开始,python3 包含在官方存储库中,因此您可以这样做

yum install python3

See https://www.liquidweb.com/kb/how-to-install-python-3-on-centos-7/https://www.liquidweb.com/kb/how-to-install-python-3-on-centos-7/

You can simply apt-get install python3 and then use -p python3 while creating your virtual environment.您可以简单地apt-get install python3然后在创建虚拟环境时使用-p python3 Installing python3 will not disturb your system python (2.7).安装 python3 不会干扰你的系统 python (2.7)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM