Centos (серверная linux)

Описание: Новости науки и техники. Всё то, о чём раньше Вы могли только мечтать. Магия современности.

dyvniy M
Автор темы, Администратор
Администратор
Аватара
dyvniy M
Автор темы, Администратор
Администратор
Возраст: 41
Репутация: 1
Лояльность: 1
Сообщения: 3579
Зарегистрирован: Ср, 10 октября 2012
С нами: 11 лет 6 месяцев
Профессия: Программист
Откуда: Россия, Москва
ICQ Сайт Skype ВКонтакте

#1 dyvniy » Ср, 22 февраля 2017, 08:10:12

Установка питона 3
http://idroot.net/tutorials/how-to-install-python-3-on-centos-7/
Спойлер
Home » Linux » Centos » How To Install Python 3 on CentOS 7
How To Install Python 3 on CentOS 7
r00t January 31, 2016
Install Python 3 on CentOS 7

In this tutorial we will show you how to install and configuration Python 3 on CentOS 7 server. As of the latest CentOS 7, the default Python version still remains python 2.7, and python3 is not available in base repositories. If you need to use python3 as part of Python application dependency, there are several ways to install python3 on CentOS.

This article assumes you have at least basic knowledge of linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step installation Python on a CentOS 7 server.

Install Python 3 on CentOS 7

Step 1. First let’s start by ensuring your system is up-to-date.


yum -y update
yum groupinstall "Development tools"
1
2
yum -y update
yum groupinstall "Development tools"
Step 2. Installing Python.

Method One: Build and Install Python3 from the Source

First thing to do is to go to Python’s download page and download the latest stable version of Python, At the moment of writing this article it is version 3.5.1:


wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz
1
wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz
Extract source archive and build:


tar xzf Python-3.5.1.tgz
cd Python-3.5.1
1
2
tar xzf Python-3.5.1.tgz
cd Python-3.5.1
Next, we are going to configure the installation directory on /usr/local, We can change the path:


./configure --prefix=/usr/local
1
./configure --prefix=/usr/local
Building and installing Python through below make altinstall command , this command will replace the python , which is using by the server:


make altinstall
1
make altinstall
You now should be all set to use your newly compiled python version:


# python3.5 –V
Python 3.5.1
1
2
# python3.5 –V
Python 3.5.1
Method Two: Install Python3 from EPEL Repository

First, you need to enable EPEL repository on your system:


yum install epel-release
1
yum install epel-release
Then install python 3.4 and its libraries using yum:


yum install python34
1
yum install python34
Method Three: Install Python3 from Software Collections (SCL)

The first step is to install the utilities needed to manage collections:


yum -y install scl-utils
1
yum -y install scl-utils
Once you enable the SCL repository, go ahead and install python3 as follows:


yum -y install python33
1
yum -y install python33
Python 3.3 will become accessible by launching a new shell instance using the Software Collection scl command:


scl enable python33 bash
1
scl enable python33 bash
Additional Python libraries and tools, such as pip, can now be installed:


easy_install pip
1
easy_install pip
Congratulation’s! You have successfully installed Python. Thanks for using this tutorial for installing Python 3 on CentOS 7 system. For additional help or useful information, we recommend you to check the official Python web site.
Изображение

dyvniy M
Автор темы, Администратор
Администратор
Аватара
dyvniy M
Автор темы, Администратор
Администратор
Возраст: 41
Репутация: 1
Лояльность: 1
Сообщения: 3579
Зарегистрирован: Ср, 10 октября 2012
С нами: 11 лет 6 месяцев
Профессия: Программист
Откуда: Россия, Москва
ICQ Сайт Skype ВКонтакте

#2 dyvniy » Ср, 22 февраля 2017, 11:31:15

Установка питона 3.5
http://www.codeghar.com/blog/install-latest-python-on-centos-7.html
Спойлер
Install Latest Python on CentOS 7
Hamza Sheikh Updated 2016-04-20 06:25 UTC Published 2016-04-13 05:07 UTC Source
There are many options to install newer Python on CentOS, including building from source, installing from EPEL, installing from Software Collections (SCL), installing third party rpm package, etc. These all work to some degree of success. I had a different use case and could not find a pre-built rpm package to fit it.

My use case had these restraints:

Install newer Python alongside the default system version
Install multiple Python versions simultaneously
Install the latest release from upstream Python project not just the latest release from a repository (repo)
Do not build from source unless absolutely necessary
Unfortunately, even after trying for a good part of three days I could not take a source rpm (srpm) and modify it to fit these restraints. Some of my assumptions that proved false include:

Edit ~/.rpmmacros replace _prefix /usr with _prefix /usr/local
Make the package relocatable with Prefix: /usr/local in the spec file
The easiest way I found to get the latest Python 2.7 was to replace the system version with a newer rpm package. Python 3 is in a much better position when you use the IUS repo.

UPDATE (2016-04-20): I have created a companion git repo that provides a quick start alternative to the manual steps described here.

Install Latest Python 3
The IUS repo community has done a wonderful job of providing the absolute latest Python 3 releases as rpm packages for RHEL and CentOS that easily install alongside the default system Python.

$ sudo yum install -y https://centos7.iuscommunity.org/ius-release.rpm
$ sudo yum update
Install Python 3.4

$ sudo yum install -y python34u python34u-libs python34u-devel python34u-pip
$ which -a python3.4
/bin/python3.4
/usr/bin/python3.4
Install Python 3.5

$ sudo yum install -y python35u python35u-libs python35u-devel python35u-pip
$ which -a python3.5
/bin/python3.5
/usr/bin/python3.5
Install Latest Python 2
SCL was on Python 2.7.8 at the time of writing while the latest upstream release was 2.7.11. IUS does not provide Python 2 packages. Since I didn't want to build from source myself I had to come up with a better solution. I like to think I found that solution.

I believe in building on the work of others in the free software community. For this reason I decided to look at Fedora. They build newer releases regularly. Why not take their rpm and make a few changes to differentiate my version from theirs to prevent any conflicts when installed? This is the path I chose and it was pretty successful.

Here I'll provide a step-by-step process of what I did to rebuild a custom rpm from the source rpm built by the Fedora project.

Step 1
Install CentOS 7 in a virtual machine (VM) and install all updates.

Step 2
Install packages to prepare for building an rpm package.

$ sudo yum install -y rpm-build

$ sudo yum install -y redhat-rpm-config

$ sudo yum install -y yum-utils

$ sudo yum groupinstall -y "Development Tools"
Step 3
Install prerequisites for building Python 2.7.11.

$ sudo yum-builddep -y python-2.7.11-4.fc24.src.rpm
Step 4
Create necessary directory structure.

$ mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
Step 5
Fedora has a build system, Koji, that provides access to all public builds. Latest Python available there was 2.7.11 build 4 for Fedora 24.

Download the srpm to the directory structure created in step 4.

$ cd ~/rpmbuild/SRPMS
$ curl -O https://kojipkgs.fedoraproject.org//packages/pyth ... c/python-2.7.11-4.fc24.src.rpm
Step 6a
"Install" (unpack) the srpm in the directory structure created.

$ cd ~/rpmbuild/SRPMS
$ rpm -i python-2.7.11-4.fc24.src.rpm
Step 6b
If you don't want to customize anything and don't mind the build taking about 90 minutes (as tests are run after the build is done) you can rebuild like so

$ cd ~/rpmbuild/SRPMS
$ rpmbuild --rebuild python-2.7.11-4.fc24.src.rpm
If you do this then ignore steps 7 & 8 and skip to step 9.

Step 7
Optional: Patch python.spec with your changes.

$ cd ~/rpmbuild/SPECS/
$ vim python.spec
.. Your Changes Here ..
Step 8
Build rpm and srpm from the spec file.

Warning: On my VM it took more than 90 minutes for the builds to complete and tests to run. To disable tests set %global run_selftest_suite to 0.

$ cd ~/rpmbuild/SPECS/
$ sed -i -e "s/^%global run_selftest_suite 1/%global run_selftest_suite 0/g" python.spec # OPTIONAL
$ rpmbuild -ba python.spec
You may also build rpms from the newly created srpm. It's up to you.

$ cd ~/rpmbuild/SRPMS/
$ rpmbuild --rebuild python2711-2.7.11-4.el7.centos.src.rpm
Step 9
All rpms are located in ~/rpmbuild/RPMS/x86_64 directory. Install them from the file system or even better copy them to a local repo to let other machines install from there as well.

$ cd ~/rpmbuild/RPMS/
$ sudo yum localinstall --nogpgcheck python-libs-2.7.11-4.el7.centos.x86_64.rpm python-2.7.11-4.el7.centos.x86_64.rpm
This will replace the system-installed version. For newer releases this process must be repeated every time.

Epilogue
For Python 3 I could have taken a Python 3 srpm from Koji and re-built it just like I did for Python 2. Unfortunately, its build requirements included packages that I would have needed from Koji as well. That was a rabbit hole I didn't want to climb down. Therefore, I used the commendable work of the IUS community.

I'm disappointed that there's no easy way to take an rpm, make a few changes, and install it in /usr/local. This is a use case sorely missing in the Fedora, RHEL, and CentOS communities.

I'm also glad that I could build on the work of communities and that the RHEL ecosystem is open enough to allow such quick turnaround for installing latest Python releases.

A good rule of thumb: use IUS to install Python from packages that don't conflict with stock CentOS packages and to rebuild srpms from Fedora when they are not available on IUS or EPEL.

Код: Выделить всё

su
yum install -y https://centos7.iuscommunity.org/ius-release.rpm
yum update
Install Python 3.5

Код: Выделить всё

yum install -y python35u python35u-libs python35u-devel python35u-pip
which -a python3.5
/bin/python3.5
/usr/bin/python3.5
Изображение


Название раздела: Технокалипсис
Описание: Новости науки и техники. Всё то, о чём раньше Вы могли только мечтать. Магия современности.

Быстрый ответ


Введите код в точности так, как вы его видите. Регистр символов не имеет значения.
Код подтверждения
:) ;) :hihi: :P :hah: :haha: :angel: :( :st: :_( :cool: 8-| :beee: :ham: :rrr: :grr: :* :secret: :stupid: :music: Ещё смайлики…
   

Вернуться в «Технокалипсис»

Кто сейчас на форуме (по активности за 15 минут)

Сейчас этот раздел просматривают: 16 гостей