在 RHEL 上安装 Python 3
我正在尝试使用以下步骤在 RHEL 上安装 python3:
yum search python3
返回 No matches find for: python3
其次:
yum search python
搜索结果均不包含 python3。接下来我应该尝试什么?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(19)
从 RPM 安装通常更好,因为:
解决方案 1:红帽和EPEL 存储库
Red Hat 通过 EPEL 存储库添加了:
[EPEL] 如何安装 Python 3.4在 CentOS 6 上
您可以使用
pyvenv
创建您的 virtualenv:[EPEL] 如何在 CentOS 7 上安装 Python
3.6 CentOS7,
pip3.6
作为软件包提供:)您可以使用
pyvenv
创建您的 virtualenv:如果您使用
pyvenv< /code> 脚本,您将收到警告:
解决方案 2:IUS 社区存储库
IUS 社区为 RHEL 和 Linux 提供了一些最新的软件包。 CentOS。背后的人来自 Rackspace,所以我认为他们非常值得信赖...
https://ius.io/
在这里检查适合您的存储库:
https://ius.io/setup
[IUS] 如何安装 Python 3.6在 CentOS 6 上
您可以创建您的virtualenv 使用
pyvenv
:[IUS] 如何在 CentOS 7 上安装 Python 3.6
您可以使用
pyvenv
创建您的 virtualenv :Installing from RPM is generally better, because:
Solution 1: Red Hat & EPEL repositories
Red Hat has added through the EPEL repository:
[EPEL] How to install Python 3.4 on CentOS 6
You can create your virtualenv using
pyvenv
:[EPEL] How to install Python 3.6 on CentOS 7
With CentOS7,
pip3.6
is provided as a package :)You can create your virtualenv using
pyvenv
:If you use the
pyvenv
script, you'll get a WARNING:Solution 2: IUS Community repositories
The IUS Community provides some up-to-date packages for RHEL & CentOS. The guys behind are from Rackspace, so I think that they are quite trustworthy...
https://ius.io/
Check the right repo for you here:
https://ius.io/setup
[IUS] How to install Python 3.6 on CentOS 6
You can create your virtualenv using
pyvenv
:[IUS] How to install Python 3.6 on CentOS 7
You can create your virtualenv using
pyvenv
:手动安装 python 很容易(即从源代码构建):
下载(Python 上可能有更新的版本.org):
<预> <代码> $ wget https://www.python.org/ftp/python/3.4.3/Python-3.4.3.tar.xz
解压
<前><代码> $ tar xf Python-3.*
$ cd Python-3.*
准备编译
<预置><代码> $ ./configure
构建
<前><代码> $ make
安装
<前><代码> $ make install
或者,如果您不想覆盖
python
可执行文件(更安全,至少在某些发行版上yum
需要python
为 2 .x,例如 RHEL6) - 您可以使用altinstall
将python3.*
安装为系统默认的并发实例:<预置><代码> $ make altinstall
现在,如果您想要替代安装目录,您可以经过
--prefix
到configure
命令。示例:要在 /opt/local 中“安装”Python,只需添加
--prefix=/opt/local
。在
make install
步骤之后:为了使用新安装的 Python,您可能仍然需要将 [prefix]/bin 添加到$PATH
并[prefix]/lib 到$LD_LIBRARY_PATH
(取决于您传递的--prefix
)It is easy to install python manually (i.e. build from source):
Download (there may be newer releases on Python.org):
Unzip
Prepare compilation
Build
Install
OR if you don't want to overwrite the
python
executable (safer, at least on some distrosyum
needspython
to be 2.x, such as for RHEL6) - you can installpython3.*
as a concurrent instance to the system default with analtinstall
:Now if you want an alternative installation directory, you can pass
--prefix
to theconfigure
command.Example: for 'installing' Python in /opt/local, just add
--prefix=/opt/local
.After the
make install
step: In order to use your new Python installation, it could be, that you still have to add the [prefix]/bin to the$PATH
and [prefix]/lib to the$LD_LIBRARY_PATH
(depending of the--prefix
you passed)除了gecco的答案之外,我会将步骤3从: 更改
为:
然后安装后您还可以:
这是为了确保安装不会与使用yum安装的python发生冲突。
请参阅我在互联网上找到的解释:
http ://www.hosting.com/support/linux/installing-python-3-on-centosredhat-5x-from-source
In addition to gecco's answer I would change step 3 from:
to:
Then after installation you could also:
It is to ensure that installation will not conflict with python installed with yum.
See explanation I have found on Internet:
http://www.hosting.com/support/linux/installing-python-3-on-centosredhat-5x-from-source
除了 Python 2.7 和 3.3 之外,红帽软件集合现在还包括 Python 3.4 - 所有这些都可以在 RHEL 6 和 7 上运行。RHSCL
2.0 文档位于 https://access.redhat.com/documentation/en-US/Red_Hat_Software_Collections/
另外还有很多文章位于developerblog.redhat.com。
使用SCL
yum 存储库可能比其他 yum 存储库更好,因为 RPM 是由 Redhat 开发/测试的(即第一方 RPM 而不是第三方) )。编辑
遵循这些在 RHEL 6/7 或 CentOS 6/7 上安装 Python 3.4 的说明:
更新 2021-08-16:
rhel
和centos
版本 7 现在默认使用 python 3.6,我相信Along with Python 2.7 and 3.3, Red Hat Software Collections now includes Python 3.4 - all work on both RHEL 6 and 7.
RHSCL 2.0 docs are at https://access.redhat.com/documentation/en-US/Red_Hat_Software_Collections/
Plus lot of articles at developerblog.redhat.com.
<opinion>
Using theSCL
yum repos may be better than other yum repos because the RPMs are developed/tested by Redhat (i.e. first-party RPMs instead of third-party).</opinion>
edit
Follow these instructions to install Python 3.4 on RHEL 6/7 or CentOS 6/7:
UPDATE 2021-08-16:
rhel
andcentos
version 7 are now on python 3.6 by default i believe使用 SCL 存储库。
(每次您想要使用 python27 而不是系统默认值时,都必须运行最后一个命令。)
Use the SCL repos.
(This last command will have to be run each time you want to use python27 rather than the system default.)
Python3 最近作为 Python34 添加到 EPEL7。
目前正在努力制定关于如何在 EPEL7 中为 Python3 打包内容的打包指南。
请参阅 https://bugzilla.redhat.com/show_bug.cgi?id=1219411
和 https://lists.fedoraproject.org/pipermail/python-devel/2015-July /000721.html
Python3 was recently added to EPEL7 as Python34.
There is ongoing (currently) effort to make packaging guidelines about how to package things for Python3 in EPEL7.
See https://bugzilla.redhat.com/show_bug.cgi?id=1219411
and https://lists.fedoraproject.org/pipermail/python-devel/2015-July/000721.html
您可以从以下位置下载 RHEL6 / CentOS6 的源 RPM 和二进制 RPM:
此处
这是最新 Fedora 开发的反向移植
源 rpm 到 RHEL6 / CentOS6
You can download a source RPMs and binary RPMs for RHEL6 / CentOS6 from
here
This is a backport from the newest Fedora development
source rpm to RHEL6 / CentOS6
如果您使用 RHEL 并且想要 Red Hat 支持的 Python,请使用 Red Hat Software Collections (RHSCL)。 Red Hat 不支持 EPEL 和 IUS 软件包。另外,上面的许多答案都指向 CentOS 软件集合。虽然您可以安装这些软件包,但它们不是 RHEL 的 Red Hat 支持的软件包。
另外,投票最高的答案给出了不好的建议 - 在 RHEL 上,您不想更改
/usr/bin/python
、/usr/bin/python2
因为您可能会破坏yum
和其他 RHEL 管理工具。看一下/bin/yum
,它是一个以#!/usr/bin/python
开头的Python脚本。如果您从源代码编译 Python,请勿以 root 身份执行make install
。这将覆盖/usr/bin/python
。如果您破坏了yum
,则恢复系统可能会很困难。有关更多信息,请参阅如何安装 Python 3、pip、venv developers.redhat.com 上 RHEL 上的 virtualenv 和 pipelinev。它涵盖了从 RHSCL 安装和使用 Python 3、使用 Python 虚拟环境以及在 RHEL 上使用软件集合和使用 Python 的一些技巧。
简而言之,要通过 Red Hat 软件集合安装 Python 3.6:
要使用软件集合,您必须启用它:
但是,如果您希望永久启用 Python 3,您可以将以下内容添加到 ~/.bashrc,然后注销并再次回来。现在,Python 3 已永久在您的路径中。
注意:执行此操作后,输入
python
现在将为您提供 Python 3.6,而不是 Python 2.7。有关所有这些内容以及更多详细信息,请参阅上面的文章。
If you are on RHEL and want a Red Hat supported Python, use Red Hat Software collections (RHSCL). The EPEL and IUS packages are not supported by Red Hat. Also many of the answers above point to the CentOS software collections. While you can install those, they aren't the Red Hat supported packages for RHEL.
Also, the top voted answer gives bad advice - On RHEL you do not want to change
/usr/bin/python
,/usr/bin/python2
because you will likely breakyum
and other RHEL admin tools. Take a look at/bin/yum
, it is a Python script that starts with#!/usr/bin/python
. If you compile Python from source, do not do amake install
as root. That will overwrite/usr/bin/python
. If you breakyum
it can be difficult to restore your system.For more info, see How to install Python 3, pip, venv, virtualenv, and pipenv on RHEL on developers.redhat.com. It covers installing and using Python 3 from RHSCL, using Python Virtual Environments, and a number of tips for working with software collections and working with Python on RHEL.
In a nutshell, to install Python 3.6 via Red Hat Software Collections:
To use a software collection you have to enable it:
However if you want Python 3 permanently enabled, you can add the following to your ~/.bashrc and then log out and back in again. Now Python 3 is permanently in your path.
Note: once you do that, typing
python
now gives you Python 3.6 instead of Python 2.7.See the above article for all of this and a lot more detail.
我看到所有的答案都是要求从代码编译 python3 或安装二进制 RPM 包。这是启用 EPEL (Extra Packages for Enterprise Linux) 然后使用 yum 安装 python 的另一个答案。 RHEL 7.5 (Maipo) 的步骤
另请参阅链接
I see all the answers as either asking to compile python3 from code or installing the binary RPM package. Here is another answer to enable EPEL (Extra Packages for Enterprise Linux) and then install python using yum. Steps for RHEL 7.5 (Maipo)
Also see link
我在使用 python 2.7 时遇到了同样的问题。按照以下步骤成功升级到3.6。
您也可以尝试这个 -
升级前查看版本是 2.x
<前><代码>python --版本
Python 2.7.5
使用下面的命令将你的python升级到3.x版本-
yum 安装 python3x
将 x 替换为您想要的版本号。
ie安装python 3.6执行
之后,如果您想将此 python 设置为默认版本,则在 bashrc 文件中添加
vi ~/.bashrc
执行 bash 命令以应用设置
<前><代码>bash
现在你可以看到下面的版本
<前><代码>python --版本
Python 3.6.3
I was having the same issue using the python 2.7. Follow the below steps to upgrade successfully to 3.6.
You can also try this one-
See before upgrading version is 2.x
Use below command to upgrade your python to 3.x version-
yum install python3x
replace x with the version number you want.
i.e. for installing python 3.6 execute
After that if you want to set this python for your default version then in bashrc file add
vi ~/.bashrc
execute bash command to apply the settings
Now you can see the version below
以下是我安装 Python3 的步骤:
Here are the steps i followed to install Python3:
Software Collections 使用 Python 3.5 的三个步骤:
请注意 sudo 是最后一个命令不需要。现在我们可以看到 python 3 是当前 shell 的默认设置:
如果您希望将 Python 2 作为当前 shell 的默认设置,只需跳过最后一个命令即可。
现在,假设您的 Python 3 脚本给出了类似
/usr/bin/env: python3: No such file or directory
的错误。这是因为安装通常是在不寻常的路径上进行的:上面的路径通常是符号链接。如果您希望在启动时将
python3
自动添加到所有用户的$PATH
中,一种方法是添加如下文件:包含以下内容:
其中 现在重新启动后,如果我们这样做
它应该可以正常工作。一个例外是 Jenkins 服务器中自动生成的用户,例如“jenkins”,它没有 shell。在这种情况下,在脚本中手动添加
$PATH
的路径是一种方法。最后,如果您使用
sudo pip3
安装软件包,但它告诉您无法找到 pip3,则可能是您有 secure_path em> 在 /etc/sudoers 中。使用 sudo visudo 检查应该可以确认这一点。要在运行命令时临时使用标准PATH,您可以执行以下操作,例如:请参阅这个问题了解更多详细信息。
注意:Software Collections 有一个较新的 Python 3.6,但我现在不推荐它,因为我在尝试安装 Pycurl 时遇到了很大的麻烦。对于 Python 3.5,这不是问题,因为我刚刚执行了 sudo yum install sclo-python35-python-pycurl ,它开箱即用。
Three steps using Python 3.5 by Software Collections:
Note that sudo is not needed for the last command. Now we can see that python 3 is the default for the current shell:
Simply skip the last command if you'd rather have Python 2 as the default for the current shell.
Now let's say that your Python 3 scripts give you an error like
/usr/bin/env: python3: No such file or directory
. That's because the installation is usually done to an unusual path:The above would normally be a symlink. If you want
python3
to be automatically added to the$PATH
for all users on startup, one way to do this is adding a file like:Which would have something like:
And now after a reboot, if we do
It should just work. One exception would be an auto-generated user like "jenkins" in a Jenkins server which doesn't have a shell. In that case, manually adding the path to
$PATH
in scripts would be one way to go.Finally, if you're using
sudo pip3
to install packages, but it tells you that pip3 cannot be found, it could be that you have a secure_path in /etc/sudoers. Checking withsudo visudo
should confirm that. To temporarily use the standard PATH when running commands you can do, for example:See this question for more details.
NOTE: There is a newer Python 3.6 by Software Collections, but I wouldn't recommend it at this time, because I had major headaches trying to install Pycurl. For Python 3.5 that isn't an issue because I just did
sudo yum install sclo-python35-python-pycurl
which worked out of the box.如果您需要官方 RHEL 软件包,可以使用 RHSCL(红帽软件集合)
更多详细信息:
您必须有权访问红帽客户门户才能阅读完整文章。
If you want official RHEL packages you can use RHSCL (Red Hat Software Collections)
More details:
You have to have access to Red Hat Customer Portal to read full articles.
如果您安装了
epel-release
,yum install python34.x86_64
就可以工作,这个答案解释了如何操作,并且我确认它在RHEL 7.3
上有效yum install python34.x86_64
works if you haveepel-release
installed, which this answer explains how to, and I confirmed it worked onRHEL 7.3
对于 Amazon Linux 上的 RHEL,使用 python3 我必须这样做:
For RHEL on Amazon Linux, using python3 I had to do :
当SCL不可用时完全工作36(基于Joys输入)
最后激活环境......
然后python3
Full working 36 when SCL is not available (based on Joys input)
Finally activate the environment...
Then python3
您可以安装 miniconda (https://conda.io/miniconda.html)。这比 python 3.7 稍微多一点,但安装非常直接和简单。
您必须接受许可协议并在交互模式下选择一些选项(接受默认值)。
我相信它也可以以某种方式静默安装。
You can install miniconda (https://conda.io/miniconda.html). That's a bit more than just python 3.7 but the installation is very straightforward and simple.
You'll have to accept the license agreement and choose some options in interactive mode (accept the defaults).
I believe it can be also installed silently somehow.
对于使用 AWS EC2 RHEL 7.5 的用户,(使用 sudo)启用所需的存储库
安装 Python 3.6
安装其他依赖项
For those working on AWS EC2 RHEL 7.5, (use sudo) enable required repos
Install Python 3.6
Install other dependencies
从 RHEL 8 开始,您可以直接从官方存储库安装 python3:
您甚至可以获得 python 3.8:
As of RHEL 8, you can install python3 directly from the official repositories:
You can even get python 3.8: