Installing Python 3 on RHEL - python

I'm trying to install python3 on RHEL using the following steps:
yum search python3
Which returned No matches found for: python3
Followed by:
yum search python
None of the search results contained python3. What should I try next?

Installing from RPM is generally better, because:
you can install and uninstall (properly) python3.
the installation time is way faster. If you work in a cloud environment with multiple VMs, compiling python3 on each VMs is not acceptable.
Solution 1: Red Hat & EPEL repositories
Red Hat has added through the EPEL repository:
Python 3.4 for CentOS 6
Python 3.6 for CentOS 7
[EPEL] How to install Python 3.4 on CentOS 6
sudo yum install -y epel-release
sudo yum install -y python34
# Install pip3
sudo yum install -y python34-setuptools # install easy_install-3.4
sudo easy_install-3.4 pip
You can create your virtualenv using pyvenv:
pyvenv /tmp/foo
[EPEL] How to install Python 3.6 on CentOS 7
With CentOS7, pip3.6 is provided as a package :)
sudo yum install -y epel-release
sudo yum install -y python36 python36-pip
You can create your virtualenv using pyvenv:
python3.6 -m venv /tmp/foo
If you use the pyvenv script, you'll get a WARNING:
$ pyvenv-3.6 /tmp/foo
WARNING: the pyenv script is deprecated in favour of `python3.6 -m venv`
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
sudo yum install -y https://repo.ius.io/ius-release-el6.rpm
sudo yum install -y python36u python36u-pip
You can create your virtualenv using pyvenv:
python3.6 -m venv /tmp/foo
[IUS] How to install Python 3.6 on CentOS 7
sudo yum install -y https://repo.ius.io/ius-release-el7.rpm
sudo yum install -y python36u python36u-pip
You can create your virtualenv using pyvenv:
python3.6 -m venv /tmp/foo

It is easy to install python manually (i.e. build from source):
Download (there may be newer releases on Python.org):
$ wget https://www.python.org/ftp/python/3.4.3/Python-3.4.3.tar.xz
Unzip
$ tar xf Python-3.*
$ cd Python-3.*
Prepare compilation
$ ./configure
Build
$ make
Install
$ make install
OR if you don't want to overwrite the python executable (safer, at least on some distros yum needs python to be 2.x, such as for RHEL6) - you can install python3.* as a concurrent instance to the system default with an altinstall:
$ make altinstall
Now if you want an alternative installation directory, you can pass --prefix to the configurecommand.
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)

In addition to gecco's answer I would change step 3 from:
./configure
to:
./configure --prefix=/opt/python3
Then after installation you could also:
# ln -s /opt/python3/bin/python3 /usr/bin/python3
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

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 the SCL 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:
# 1. Install the Software Collections tools:
yum install scl-utils
# 2. Download a package with repository for your system.
# (See the Yum Repositories on external link. For RHEL/CentOS 6:)
wget https://www.softwarecollections.org/en/scls/rhscl/rh-python34/epel-6-x86_64/download/rhscl-rh-python34-epel-6-x86_64.noarch.rpm
# or for RHEL/CentOS 7
wget https://www.softwarecollections.org/en/scls/rhscl/rh-python34/epel-7-x86_64/download/rhscl-rh-python34-epel-7-x86_64.noarch.rpm
# 3. Install the repo package (on RHEL you will need to enable optional channel first):
yum install rhscl-rh-python34-*.noarch.rpm
# 4. Install the collection:
yum install rh-python34
# 5. Start using software collections:
scl enable rh-python34 bash
UPDATE 2021-08-16:
rhel and centos version 7 are now on python 3.6 by default i believe
the SCL yum repo has python version 3.8 as of the date of this writing 2021-08-16 (despite the question still referencing the older python 3.4 version)

Use the SCL repos.
sudo sh -c 'wget -qO- http://people.redhat.com/bkabrda/scl_python33.repo >> /etc/yum.repos.d/scl.repo'
sudo yum install python33
scl enable python27
(This last command will have to be run each time you want to use python27 rather than the system default.)

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

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

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 break yum 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 a make install as root. That will overwrite /usr/bin/python. If you break yum 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:
$ su -
# subscription-manager repos --enable rhel-7-server-optional-rpms \
--enable rhel-server-rhscl-7-rpms
# yum -y install #development
# yum -y install rh-python36
# yum -y install rh-python36-numpy \
rh-python36-scipy \
rh-python36-python-tools \
rh-python36-python-six
To use a software collection you have to enable it:
scl enable rh-python36 bash
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.
# Add RHSCL Python 3 to my login environment
source scl_source enable rh-python36
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.

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)
yum install wget –y
wget https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-XX.noarch.rpm # Verify actual RPM name by browsing dir over browser
rpm –ivh epel-*.rpm
yum install python36
Also see link

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
python --version
Python 2.7.5
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
yum install python36
After that if you want to set this python for your default version then in bashrc file add
vi ~/.bashrc
alias python='python3.6'
execute bash command to apply the settings
bash
Now you can see the version below
python --version
Python 3.6.3

Here are the steps i followed to install Python3:
yum install wget
wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tar.xz
sudo tar xvf Python-3.*
cd Python-3.*
sudo ./configure --prefix=/opt/python3
sudo make
sudo make install
sudo ln -s /opt/python3/bin/python3 /usr/bin/python3
$ /usr/bin/python3
Python 3.6.0

Three steps using Python 3.5 by Software Collections:
sudo yum install centos-release-scl
sudo yum install rh-python35
scl enable rh-python35 bash
Note that sudo is not needed for the last command. Now we can see that python 3 is the default for the current shell:
python --version
Python 3.5.1
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:
/opt/rh/rh-python35/root/bin/python3
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:
sudo vim /etc/profile.d/rh-python35.sh
Which would have something like:
#!/bin/bash
PATH=$PATH:/opt/rh/rh-python35/root/bin/
And now after a reboot, if we do
python3 --version
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 with sudo visudo should confirm that. To temporarily use the standard PATH when running commands you can do, for example:
sudo env "PATH=$PATH" pip3 --version
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.

If you want official RHEL packages you can use RHSCL (Red Hat Software Collections)
More details:
Guide to Python 3.3 in RHSCL 1.1
How to access and download Red Hat Software Collections (RHSCL) and/or Red Hat Developer Toolset (DTS)?
You have to have access to Red Hat Customer Portal to read full articles.

yum install python34.x86_64 works if you have epel-release installed, which this answer explains how to, and I confirmed it worked on RHEL 7.3
$ cat /etc/*-release
NAME="Red Hat Enterprise Linux Server"
VERSION="7.3 (Maipo)
$ type python3
python3 is hashed (/usr/bin/python3)

For RHEL on Amazon Linux, using python3 I had to do :
sudo yum install python34-devel

Full working 36 when SCL is not available (based on Joys input)
yum install wget –y
wget https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
rpm –ivh epel-*.rpm
yum install python36
sudo yum install python34-setuptools
sudo mkdir /usr/local/lib/python3.6
sudo mkdir /usr/local/lib/python3.6/site-packages
sudo easy_install-3.6 pip
Finally activate the environment...
pyvenv-3.6 py3
source py3/bin/activate
Then python3

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.
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O
sudo yum install bzip2
bash Miniconda3-latest-Linux-x86_64.sh
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.

For those working on AWS EC2 RHEL 7.5, (use sudo) enable required repos
yum-config-manager --enable rhui-REGION-rhel-server-optional
yum-config-manager --enable rhui-REGION-rhel-server-rhscl
Install Python 3.6
yum install rh-python36
Install other dependencies
yum install rh-python36-numpy rh-python36-scipy rh-python36-python-tools rh-python36-python-six

As of RHEL 8, you can install python3 directly from the official repositories:
$ podman run --rm -ti ubi8 bash
[root#453fc5c55104 /]# yum install python3
Updating Subscription Management repositories.
Unable to read consumer identity
Subscription Manager is operating in container mode.
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
...
Installed:
platform-python-pip-9.0.3-16.el8.noarch
python3-pip-9.0.3-16.el8.noarch
python3-setuptools-39.2.0-5.el8.noarch
python36-3.6.8-2.module+el8.1.0+3334+5cb623d7.x86_64
Complete!
You can even get python 3.8:
[root#453fc5c55104 /]# yum install python38
Installed:
python38-3.8.0-6.module+el8.2.0+5978+503155c0.x86_64
python38-libs-3.8.0-6.module+el8.2.0+5978+503155c0.x86_64
python38-pip-19.2.3-5.module+el8.2.0+5979+f9f0b1d2.noarch
python38-pip-wheel-19.2.3-5.module+el8.2.0+5979+f9f0b1d2.noarch
python38-setuptools-41.6.0-4.module+el8.2.0+5978+503155c0.noarch
python38-setuptools-wheel-41.6.0-4.module+el8.2.0+5978+503155c0.noarch
Complete!

Related

Should I downgrade Python libraries for my webapp? [duplicate]

I'm trying to install python3 on RHEL using the following steps:
yum search python3
Which returned No matches found for: python3
Followed by:
yum search python
None of the search results contained python3. What should I try next?
Installing from RPM is generally better, because:
you can install and uninstall (properly) python3.
the installation time is way faster. If you work in a cloud environment with multiple VMs, compiling python3 on each VMs is not acceptable.
Solution 1: Red Hat & EPEL repositories
Red Hat has added through the EPEL repository:
Python 3.4 for CentOS 6
Python 3.6 for CentOS 7
[EPEL] How to install Python 3.4 on CentOS 6
sudo yum install -y epel-release
sudo yum install -y python34
# Install pip3
sudo yum install -y python34-setuptools # install easy_install-3.4
sudo easy_install-3.4 pip
You can create your virtualenv using pyvenv:
pyvenv /tmp/foo
[EPEL] How to install Python 3.6 on CentOS 7
With CentOS7, pip3.6 is provided as a package :)
sudo yum install -y epel-release
sudo yum install -y python36 python36-pip
You can create your virtualenv using pyvenv:
python3.6 -m venv /tmp/foo
If you use the pyvenv script, you'll get a WARNING:
$ pyvenv-3.6 /tmp/foo
WARNING: the pyenv script is deprecated in favour of `python3.6 -m venv`
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
sudo yum install -y https://repo.ius.io/ius-release-el6.rpm
sudo yum install -y python36u python36u-pip
You can create your virtualenv using pyvenv:
python3.6 -m venv /tmp/foo
[IUS] How to install Python 3.6 on CentOS 7
sudo yum install -y https://repo.ius.io/ius-release-el7.rpm
sudo yum install -y python36u python36u-pip
You can create your virtualenv using pyvenv:
python3.6 -m venv /tmp/foo
It is easy to install python manually (i.e. build from source):
Download (there may be newer releases on Python.org):
$ wget https://www.python.org/ftp/python/3.4.3/Python-3.4.3.tar.xz
Unzip
$ tar xf Python-3.*
$ cd Python-3.*
Prepare compilation
$ ./configure
Build
$ make
Install
$ make install
OR if you don't want to overwrite the python executable (safer, at least on some distros yum needs python to be 2.x, such as for RHEL6) - you can install python3.* as a concurrent instance to the system default with an altinstall:
$ make altinstall
Now if you want an alternative installation directory, you can pass --prefix to the configurecommand.
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)
In addition to gecco's answer I would change step 3 from:
./configure
to:
./configure --prefix=/opt/python3
Then after installation you could also:
# ln -s /opt/python3/bin/python3 /usr/bin/python3
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
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 the SCL 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:
# 1. Install the Software Collections tools:
yum install scl-utils
# 2. Download a package with repository for your system.
# (See the Yum Repositories on external link. For RHEL/CentOS 6:)
wget https://www.softwarecollections.org/en/scls/rhscl/rh-python34/epel-6-x86_64/download/rhscl-rh-python34-epel-6-x86_64.noarch.rpm
# or for RHEL/CentOS 7
wget https://www.softwarecollections.org/en/scls/rhscl/rh-python34/epel-7-x86_64/download/rhscl-rh-python34-epel-7-x86_64.noarch.rpm
# 3. Install the repo package (on RHEL you will need to enable optional channel first):
yum install rhscl-rh-python34-*.noarch.rpm
# 4. Install the collection:
yum install rh-python34
# 5. Start using software collections:
scl enable rh-python34 bash
UPDATE 2021-08-16:
rhel and centos version 7 are now on python 3.6 by default i believe
the SCL yum repo has python version 3.8 as of the date of this writing 2021-08-16 (despite the question still referencing the older python 3.4 version)
Use the SCL repos.
sudo sh -c 'wget -qO- http://people.redhat.com/bkabrda/scl_python33.repo >> /etc/yum.repos.d/scl.repo'
sudo yum install python33
scl enable python27
(This last command will have to be run each time you want to use python27 rather than the system default.)
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
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
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 break yum 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 a make install as root. That will overwrite /usr/bin/python. If you break yum 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:
$ su -
# subscription-manager repos --enable rhel-7-server-optional-rpms \
--enable rhel-server-rhscl-7-rpms
# yum -y install #development
# yum -y install rh-python36
# yum -y install rh-python36-numpy \
rh-python36-scipy \
rh-python36-python-tools \
rh-python36-python-six
To use a software collection you have to enable it:
scl enable rh-python36 bash
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.
# Add RHSCL Python 3 to my login environment
source scl_source enable rh-python36
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.
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)
yum install wget –y
wget https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-XX.noarch.rpm # Verify actual RPM name by browsing dir over browser
rpm –ivh epel-*.rpm
yum install python36
Also see link
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
python --version
Python 2.7.5
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
yum install python36
After that if you want to set this python for your default version then in bashrc file add
vi ~/.bashrc
alias python='python3.6'
execute bash command to apply the settings
bash
Now you can see the version below
python --version
Python 3.6.3
Here are the steps i followed to install Python3:
yum install wget
wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tar.xz
sudo tar xvf Python-3.*
cd Python-3.*
sudo ./configure --prefix=/opt/python3
sudo make
sudo make install
sudo ln -s /opt/python3/bin/python3 /usr/bin/python3
$ /usr/bin/python3
Python 3.6.0
Three steps using Python 3.5 by Software Collections:
sudo yum install centos-release-scl
sudo yum install rh-python35
scl enable rh-python35 bash
Note that sudo is not needed for the last command. Now we can see that python 3 is the default for the current shell:
python --version
Python 3.5.1
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:
/opt/rh/rh-python35/root/bin/python3
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:
sudo vim /etc/profile.d/rh-python35.sh
Which would have something like:
#!/bin/bash
PATH=$PATH:/opt/rh/rh-python35/root/bin/
And now after a reboot, if we do
python3 --version
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 with sudo visudo should confirm that. To temporarily use the standard PATH when running commands you can do, for example:
sudo env "PATH=$PATH" pip3 --version
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.
If you want official RHEL packages you can use RHSCL (Red Hat Software Collections)
More details:
Guide to Python 3.3 in RHSCL 1.1
How to access and download Red Hat Software Collections (RHSCL) and/or Red Hat Developer Toolset (DTS)?
You have to have access to Red Hat Customer Portal to read full articles.
yum install python34.x86_64 works if you have epel-release installed, which this answer explains how to, and I confirmed it worked on RHEL 7.3
$ cat /etc/*-release
NAME="Red Hat Enterprise Linux Server"
VERSION="7.3 (Maipo)
$ type python3
python3 is hashed (/usr/bin/python3)
For RHEL on Amazon Linux, using python3 I had to do :
sudo yum install python34-devel
Full working 36 when SCL is not available (based on Joys input)
yum install wget –y
wget https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
rpm –ivh epel-*.rpm
yum install python36
sudo yum install python34-setuptools
sudo mkdir /usr/local/lib/python3.6
sudo mkdir /usr/local/lib/python3.6/site-packages
sudo easy_install-3.6 pip
Finally activate the environment...
pyvenv-3.6 py3
source py3/bin/activate
Then python3
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.
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O
sudo yum install bzip2
bash Miniconda3-latest-Linux-x86_64.sh
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.
For those working on AWS EC2 RHEL 7.5, (use sudo) enable required repos
yum-config-manager --enable rhui-REGION-rhel-server-optional
yum-config-manager --enable rhui-REGION-rhel-server-rhscl
Install Python 3.6
yum install rh-python36
Install other dependencies
yum install rh-python36-numpy rh-python36-scipy rh-python36-python-tools rh-python36-python-six
As of RHEL 8, you can install python3 directly from the official repositories:
$ podman run --rm -ti ubi8 bash
[root#453fc5c55104 /]# yum install python3
Updating Subscription Management repositories.
Unable to read consumer identity
Subscription Manager is operating in container mode.
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
...
Installed:
platform-python-pip-9.0.3-16.el8.noarch
python3-pip-9.0.3-16.el8.noarch
python3-setuptools-39.2.0-5.el8.noarch
python36-3.6.8-2.module+el8.1.0+3334+5cb623d7.x86_64
Complete!
You can even get python 3.8:
[root#453fc5c55104 /]# yum install python38
Installed:
python38-3.8.0-6.module+el8.2.0+5978+503155c0.x86_64
python38-libs-3.8.0-6.module+el8.2.0+5978+503155c0.x86_64
python38-pip-19.2.3-5.module+el8.2.0+5979+f9f0b1d2.noarch
python38-pip-wheel-19.2.3-5.module+el8.2.0+5979+f9f0b1d2.noarch
python38-setuptools-41.6.0-4.module+el8.2.0+5978+503155c0.noarch
python38-setuptools-wheel-41.6.0-4.module+el8.2.0+5978+503155c0.noarch
Complete!

ElasticBeanstalk PHP with Python - Install packages with pip [duplicate]

I want to install pip. It should support Python 3, but it requires setuptools, which is available only for Python 2.
How can I install pip with Python 3?
edit: Manual installation and use of setuptools is not the standard process anymore.
If you're running Python 2.7.9+ or Python 3.4+
Congrats, you should already have pip installed. If you do not, read onward.
If you're running a Unix-like System
You can usually install the package for pip through your package manager if your version of Python is older than 2.7.9 or 3.4, or if your system did not include it for whatever reason.
Instructions for some of the more common distros follow.
Installing on Debian (Wheezy and newer) and Ubuntu (Trusty Tahr and newer) for Python 2.x
Run the following command from a terminal:
sudo apt-get install python-pip
Installing on Debian (Wheezy and newer) and Ubuntu (Trusty Tahr and newer) for Python 3.x
Run the following command from a terminal:
sudo apt-get install python3-pip
Note:
On a fresh Debian/Ubuntu install, the package may not be found until you do:
sudo apt-get update
Installing pip on CentOS 7 for Python 2.x
On CentOS 7, you have to install setup tools first, and then use that to install pip, as there is no direct package for it.
sudo yum install python-setuptools
sudo easy_install pip
Installing pip on CentOS 7 for Python 3.x
Assuming you installed Python 3.4 from EPEL, you can install Python 3's setup tools and use it to install pip.
# First command requires you to have enabled EPEL for CentOS7
sudo yum install python34-setuptools
sudo easy_install pip
If your Unix/Linux distro doesn't have it in package repos
Install using the manual way detailed below.
The manual way
If you want to do it the manual way, the now-recommended method is to install using the get-pip.py script from pip's installation instructions.
Install pip
To install pip, securely download get-pip.py
Then run the following (which may require administrator access):
python get-pip.py
If setuptools is not already installed, get-pip.py will install setuptools for you.
I was able to install pip for python 3 on Ubuntu just by running sudo apt-get install python3-pip.
Python 3.4+ and Python 2.7.9+
Good news! Python 3.4 (released March 2014) ships with Pip. This is the best feature of any Python release. It makes the community's wealth of libraries accessible to everyone. Newbies are no longer excluded by the prohibitive difficulty of setup. In shipping with a package manager, Python joins Ruby, Nodejs, Haskell, Perl, Go--almost every other contemporary language with a majority open-source community. Thank you Python.
Of course, that doesn't mean Python packaging is problem solved. The experience remains frustrating. I discuss this at Does Python have a package/module management system?
Alas for everyone using an earlier Python. Manual instructions follow.
Python ≤ 2.7.8 and Python ≤ 3.3
Follow my detailed instructions at https://stackoverflow.com/a/12476379/284795 . Essentially
Official instructions
Per https://pip.pypa.io/en/stable/installing.html
Download get-pip.py, being careful to save it as a .py file rather than .txt. Then, run it from the command prompt.
python get-pip.py
You possibly need an administrator command prompt to do this. Follow http://technet.microsoft.com/en-us/library/cc947813(v=ws.10).aspx
For me, this installed Pip at C:\Python27\Scripts\pip.exe. Find pip.exe on your computer, then add its folder (eg. C:\Python27\Scripts) to your path (Start / Edit environment variables). Now you should be able to run pip from the command line. Try installing a package:
pip install httpie
There you go (hopefully)!
if you're using python 3.4+
just type:
python3 -m pip
For Ubuntu 12.04 or older,
sudo apt-get install python3-pip
won't work. Instead, use:
sudo apt-get install python3-setuptools ca-certificates
sudo easy_install3 pip
Update 2015-01-20:
As per https://pip.pypa.io/en/latest/installing.html the current way is:
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
I think that should work for any version
Original Answer:
wget http://python-distribute.org/distribute_setup.py
python distribute_setup.py
easy_install pip
Single Python in system
To install packages in Python always follow these steps:
If the package is for python 2.x: sudo python -m pip install [package]
If the package is for python 3.x: sudo python3 -m pip install [package]
Note: This is assuming no alias is set for python
Through this method, there will be no confusion regarding which python version is receiving the package.
Multiple Pythons/Virtual Envs
Say you have python3 ↔ python3.6 and python3.7 ↔ python3.7
To install for python3.6: sudo python3 -m pip install [package]
To instal for python3.7: sudo python3.7 -m pip install [package]
This is essentially the same method as shown previously.
Note 1
How to find which python? Do one of the following:
~ » python3 -c "import sys; print(sys.version)"
3.9.5 (default, Nov 18 2021, 16:00:48)
your python3 command spawns:
~ » python3
Python 3.9.5 (default, Nov 18 2021, 16:00:48)
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Notice python 3.9.5 in the second line.
or say you are using virtual env and see where your python points to:
» which python
/home/ganesh/os/np-test/bin/python
Note 2
Change what python3 or python points to: https://askubuntu.com/questions/320996/how-to-make-python-program-command-execute-python-3
python3 -m ensurepip
I'm not sure when exactly this was introduced, but it's installed pip3 for me when it didn't already exist.
Older version of Homebrew
If you are on macOS, use homebrew.
brew install python3 # this installs python only
brew postinstall python3 # this command installs pip
Also note that you should check the console if the install finished successfully. Sometimes it doesn't (e.g. an error due to ownership), but people simply overlook the log.
UPDATED - Homebrew version after 1.5
According to the official Homebrew page:
On 1st March 2018 the python formula will be upgraded to Python 3.x and a python#2 formula will be added for installing Python 2.7 (although this will be keg-only so neither python nor python2 will be added to the PATH by default without a manual brew link --force). We will maintain python2, python3 and python#3 aliases.
So to install Python 3, run the following command:
brew install python3
Then, the pip is installed automatically, and you can install any package by pip install <package>.
If your Linux distro came with Python already installed, you should be able to install PIP using your system’s package manager. This is preferable since system-installed versions of Python do not play nicely with the get-pip.py script used on Windows and Mac.
Advanced Package Tool (Python 2.x)
sudo apt-get install python-pip
Advanced Package Tool (Python 3.x)
sudo apt-get install python3-pip
pacman Package Manager (Python 2.x)
sudo pacman -S python2-pip
pacman Package Manager (Python 3.x)
sudo pacman -S python-pip
Yum Package Manager (Python 2.x)
sudo yum upgrade python-setuptools
sudo yum install python-pip python-wheel
Yum Package Manager (Python 3.x)
sudo yum install python3 python3-wheel
Dandified Yum (Python 2.x)
sudo dnf upgrade python-setuptools
sudo dnf install python-pip python-wheel
Dandified Yum (Python 3.x)
sudo dnf install python3 python3-wheel
Zypper Package Manager (Python 2.x)
sudo zypper install python-pip python-setuptools python-wheel
Zypper Package Manager (Python 3.x)
sudo zypper install python3-pip python3-setuptools python3-wheel
This is the one-liner I copy-and-paste:
curl https://bootstrap.pypa.io/get-pip.py | python3
Alternate:
curl -L get-pip.io | python3
From Installing with get-pip.py:
To install pip, securely download get-pip.py by following this link:
get-pip.py. Alternatively, use
curl:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Then run the following command in the folder where you have downloaded
get-pip.py:
python get-pip.py
Warning: Be cautious if you are using a Python install that is managed
by your operating system or another package manager. get-pip.py does
not coordinate with those tools, and may leave your system in an
inconsistent state.
If you use several different versions of python try using virtualenv http://www.virtualenv.org/en/latest/virtualenv.html#installation
With the advantage of pip for each local environment.
Then install a local environment in the current directory by:
virtualenv -p /usr/local/bin/python3.3 ENV --verbose
Note that you specify the path to a python binary you have installed on your system.
Then there are now an local pythonenvironment in that folder. ./ENV
Now there should be ./ENV/pip-3.3
use
./ENV/pip-3.3 freeze to list the local installed libraries.
use ./ENV/pip-3.3 install packagename to install at the local environment.
use ./ENV/python3.3 pythonfile.py to run your python script.
Here is my way to solve this problem at ubuntu 12.04:
sudo apt-get install build-essential libncursesw5-dev libssl-dev libgdbm-dev libc6-dev libsqlite3-dev tk-dev
Then install the python3 from source code:
wget https://www.python.org/ftp/python/3.4.0/Python-3.4.0.tar.xz
tar xvf Python-3.4.0.tar.xz
cd Python-3.4.0
./configure
make
make test
sudo make install
When you finished installing all of them, pip3 will get installed automatically.
This is what I did on OS X Mavericks to get this to work.
Firstly, have brew installed
Install python 3.4
brew install python3
Then I get the latest version of distribute:
wget https://pypi.python.org/packages/source/d/distribute/distribute-0.7.3.zip#md5=c6c59594a7b180af57af8a0cc0cf5b4a
unzip distribute-0.7.3.zip
cd distribute-0.7.3
sudo setup.py install
sudo easy_install-3.4 pip
sudo pip3.4 install virtualenv
sudo pip3.4 install virtualenvwrapper
mkvirtualenv py3
python --version
Python 3.4.1
I hope this helps.
pip is installed together when you install Python. You can use
sudo pip install (module)
or
python3 -m pip install (module).
Please follow below steps to install python 3 with pip:
Step 1 : Install Python from download here
Step 2 : you’ll need to download get-pip.py
Step 3 : After download get-pip.py , open your commant prompt and go to directory where your get-pip.py file saved .
Step 4 : Enter command python get-pip.py in cmd.
Step 5 : Pip installed successfully , Verify pip installation by type command in cmd pip --version
What’s New In Python 3.4
...
pip should always be available
...
By default, the commands pipX and pipX.Y will be installed on all platforms (where X.Y stands for the version of the Python installation), along with the pip Python package and its dependencies.
https://docs.python.org/3/whatsnew/3.4.html#whatsnew-pep-453
so if you have python 3.4 installed, you can just: sudo pip3 install xxx
For python3 try this:
wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | python
The good thing is that It will also detect what version of python you have (even if it's an environment of python in your custom location).
After this you can proceed normally with (for example)
pip install numpy
source:
https://pypi.python.org/pypi/setuptools/1.1.6#upgrading-from-setuptools-0-6
Assuming you are in a highly restricted computer env (such as myself) without root access or ability to install packages...
I had never setup a fresh/standalone/raw/non-root instance of Python+virtualenv before this post. I had do quite a bit of Googling to make this work.
Decide if you are using python (python2) or python3 and set your PATH correctly. (I am strictly a python3 user.) All commands below can substitute python3 for python if you are python2 user.
wget https://pypi.python.org/packages/source/v/virtualenv/virtualenv-x.y.z.tar.gz
tar -xzvf virtualenv-x.y.z.tar.gz
python3 virtualenv-x.y.z/virtualenv.py --python $(which python3) /path/to/new/virtualenv
source /path/to/new/virtualenv/bin/activate
Assumes you are using a Bourne-compatible shell, e.g., bash
Brilliantly, this virtualenv package includes a standalone version of pip and setuptools that are auto-magically installed into each new virtualenv. This solves the chicken and egg problem.
You may want to create an alias (or update your ~/.bashrc, etc.) for this final command to activate the python virtualenv during each login. It can be a pain to remember all these paths and commands.
Check your version of python now: which python3 should give: /path/to/new/virtualenv/bin/python3
Check pip is also available in the virtualenv via which pip... should give: /path/to/new/virtualenv/bin/pip
Then... pip, pip, pip!
Final tip to newbie Pythoneers: You don't think you need virtualenv when you start, but you will be happy to have it later. Helps with "what if" installation / upgrade scenarios for open source / shared packages.
Ref: https://virtualenv.pypa.io/en/latest/installation.html
To install pip, securely download get-pip.py.
Then run the following:
python get-pip.py
Be cautious if you're using a Python install that's managed by your
operating system or another package manager. get-pip.py does not
coordinate with those tools, and may leave your system in an
inconsistent state.
Refer: PIP Installation
And for Windows 8.1/10 OS Users just open cmd (command prompt)
write this : C:\Users\%USERNAME%\AppData\Local\Programs\Python\Python36-32\Scripts
then
just write this : pip3 install {name of package}
Hint: the location of folder Python36-32 may get different for new python 3.x versions
If you used the command "python get-pip.py", you should have the 'pip' function for Python3. However, 'pip' for Python2 might still be present. In my case I uninstalled 'pip', which removed it from Python2.
After that I ran "python get-pip.py" again. (Make sure that 'get-pip.py' is saved in the same folder as Python3.) The final step was to add the directory with 'pip' command to $PATH. That solved it for me.
=>Easy way to install Python any version on Ubuntu 18.04 or Ubuntu 20.04 follow these steps:-
Step 1: Update Local Repositories:-
sudo apt update
Step 2: Install Supporting Software:-
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
Step3: Create directory on your home directory To download the newest release of Python Source Code, navigate to the /python-source-files directory and use the wget command:-
mkdir python-source-files
Step 4: Download the Latest Version of Python Source Code:-
wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz
"you can change python version by just modifies this:-"3.7.5" with the version you want example:-"3.5.2"
Step 5: Extract Compressed Files:-
tar –xf Python-3.7.5.tgz
or
tar xvzf Python-3.7.5.tgz
Step 6: Test System and Optimize Python:-
cd python-3.7.5 or your version of python.
Step 7: Now configure(Using the ––optimization option speeds code execution by 10-20%.):-
./configure ––enable–optimizations
OR you can also do this also if you facing ssl error:-
./configure --with-openssl
Step 8: Install a Second Instance of Python:-
sudo make altinstall
"It is recommended that you use the altinstall method. Your Ubuntu system may have software packages dependent on Python 2.x.
OR
If you want to Overwrite Default Python Installation/version:-
sudo make install"
Step 9:Now check Python Version:-
python3 ––version
Step 10: To install pip for python3 just go with this command:-
sudo apt-get install python3-pip

Trying to install PIPX on linux [duplicate]

I want to install pip. It should support Python 3, but it requires setuptools, which is available only for Python 2.
How can I install pip with Python 3?
edit: Manual installation and use of setuptools is not the standard process anymore.
If you're running Python 2.7.9+ or Python 3.4+
Congrats, you should already have pip installed. If you do not, read onward.
If you're running a Unix-like System
You can usually install the package for pip through your package manager if your version of Python is older than 2.7.9 or 3.4, or if your system did not include it for whatever reason.
Instructions for some of the more common distros follow.
Installing on Debian (Wheezy and newer) and Ubuntu (Trusty Tahr and newer) for Python 2.x
Run the following command from a terminal:
sudo apt-get install python-pip
Installing on Debian (Wheezy and newer) and Ubuntu (Trusty Tahr and newer) for Python 3.x
Run the following command from a terminal:
sudo apt-get install python3-pip
Note:
On a fresh Debian/Ubuntu install, the package may not be found until you do:
sudo apt-get update
Installing pip on CentOS 7 for Python 2.x
On CentOS 7, you have to install setup tools first, and then use that to install pip, as there is no direct package for it.
sudo yum install python-setuptools
sudo easy_install pip
Installing pip on CentOS 7 for Python 3.x
Assuming you installed Python 3.4 from EPEL, you can install Python 3's setup tools and use it to install pip.
# First command requires you to have enabled EPEL for CentOS7
sudo yum install python34-setuptools
sudo easy_install pip
If your Unix/Linux distro doesn't have it in package repos
Install using the manual way detailed below.
The manual way
If you want to do it the manual way, the now-recommended method is to install using the get-pip.py script from pip's installation instructions.
Install pip
To install pip, securely download get-pip.py
Then run the following (which may require administrator access):
python get-pip.py
If setuptools is not already installed, get-pip.py will install setuptools for you.
I was able to install pip for python 3 on Ubuntu just by running sudo apt-get install python3-pip.
Python 3.4+ and Python 2.7.9+
Good news! Python 3.4 (released March 2014) ships with Pip. This is the best feature of any Python release. It makes the community's wealth of libraries accessible to everyone. Newbies are no longer excluded by the prohibitive difficulty of setup. In shipping with a package manager, Python joins Ruby, Nodejs, Haskell, Perl, Go--almost every other contemporary language with a majority open-source community. Thank you Python.
Of course, that doesn't mean Python packaging is problem solved. The experience remains frustrating. I discuss this at Does Python have a package/module management system?
Alas for everyone using an earlier Python. Manual instructions follow.
Python ≤ 2.7.8 and Python ≤ 3.3
Follow my detailed instructions at https://stackoverflow.com/a/12476379/284795 . Essentially
Official instructions
Per https://pip.pypa.io/en/stable/installing.html
Download get-pip.py, being careful to save it as a .py file rather than .txt. Then, run it from the command prompt.
python get-pip.py
You possibly need an administrator command prompt to do this. Follow http://technet.microsoft.com/en-us/library/cc947813(v=ws.10).aspx
For me, this installed Pip at C:\Python27\Scripts\pip.exe. Find pip.exe on your computer, then add its folder (eg. C:\Python27\Scripts) to your path (Start / Edit environment variables). Now you should be able to run pip from the command line. Try installing a package:
pip install httpie
There you go (hopefully)!
if you're using python 3.4+
just type:
python3 -m pip
For Ubuntu 12.04 or older,
sudo apt-get install python3-pip
won't work. Instead, use:
sudo apt-get install python3-setuptools ca-certificates
sudo easy_install3 pip
Update 2015-01-20:
As per https://pip.pypa.io/en/latest/installing.html the current way is:
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
I think that should work for any version
Original Answer:
wget http://python-distribute.org/distribute_setup.py
python distribute_setup.py
easy_install pip
Single Python in system
To install packages in Python always follow these steps:
If the package is for python 2.x: sudo python -m pip install [package]
If the package is for python 3.x: sudo python3 -m pip install [package]
Note: This is assuming no alias is set for python
Through this method, there will be no confusion regarding which python version is receiving the package.
Multiple Pythons/Virtual Envs
Say you have python3 ↔ python3.6 and python3.7 ↔ python3.7
To install for python3.6: sudo python3 -m pip install [package]
To instal for python3.7: sudo python3.7 -m pip install [package]
This is essentially the same method as shown previously.
Note 1
How to find which python? Do one of the following:
~ » python3 -c "import sys; print(sys.version)"
3.9.5 (default, Nov 18 2021, 16:00:48)
your python3 command spawns:
~ » python3
Python 3.9.5 (default, Nov 18 2021, 16:00:48)
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Notice python 3.9.5 in the second line.
or say you are using virtual env and see where your python points to:
» which python
/home/ganesh/os/np-test/bin/python
Note 2
Change what python3 or python points to: https://askubuntu.com/questions/320996/how-to-make-python-program-command-execute-python-3
python3 -m ensurepip
I'm not sure when exactly this was introduced, but it's installed pip3 for me when it didn't already exist.
Older version of Homebrew
If you are on macOS, use homebrew.
brew install python3 # this installs python only
brew postinstall python3 # this command installs pip
Also note that you should check the console if the install finished successfully. Sometimes it doesn't (e.g. an error due to ownership), but people simply overlook the log.
UPDATED - Homebrew version after 1.5
According to the official Homebrew page:
On 1st March 2018 the python formula will be upgraded to Python 3.x and a python#2 formula will be added for installing Python 2.7 (although this will be keg-only so neither python nor python2 will be added to the PATH by default without a manual brew link --force). We will maintain python2, python3 and python#3 aliases.
So to install Python 3, run the following command:
brew install python3
Then, the pip is installed automatically, and you can install any package by pip install <package>.
If your Linux distro came with Python already installed, you should be able to install PIP using your system’s package manager. This is preferable since system-installed versions of Python do not play nicely with the get-pip.py script used on Windows and Mac.
Advanced Package Tool (Python 2.x)
sudo apt-get install python-pip
Advanced Package Tool (Python 3.x)
sudo apt-get install python3-pip
pacman Package Manager (Python 2.x)
sudo pacman -S python2-pip
pacman Package Manager (Python 3.x)
sudo pacman -S python-pip
Yum Package Manager (Python 2.x)
sudo yum upgrade python-setuptools
sudo yum install python-pip python-wheel
Yum Package Manager (Python 3.x)
sudo yum install python3 python3-wheel
Dandified Yum (Python 2.x)
sudo dnf upgrade python-setuptools
sudo dnf install python-pip python-wheel
Dandified Yum (Python 3.x)
sudo dnf install python3 python3-wheel
Zypper Package Manager (Python 2.x)
sudo zypper install python-pip python-setuptools python-wheel
Zypper Package Manager (Python 3.x)
sudo zypper install python3-pip python3-setuptools python3-wheel
This is the one-liner I copy-and-paste:
curl https://bootstrap.pypa.io/get-pip.py | python3
Alternate:
curl -L get-pip.io | python3
From Installing with get-pip.py:
To install pip, securely download get-pip.py by following this link:
get-pip.py. Alternatively, use
curl:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Then run the following command in the folder where you have downloaded
get-pip.py:
python get-pip.py
Warning: Be cautious if you are using a Python install that is managed
by your operating system or another package manager. get-pip.py does
not coordinate with those tools, and may leave your system in an
inconsistent state.
If you use several different versions of python try using virtualenv http://www.virtualenv.org/en/latest/virtualenv.html#installation
With the advantage of pip for each local environment.
Then install a local environment in the current directory by:
virtualenv -p /usr/local/bin/python3.3 ENV --verbose
Note that you specify the path to a python binary you have installed on your system.
Then there are now an local pythonenvironment in that folder. ./ENV
Now there should be ./ENV/pip-3.3
use
./ENV/pip-3.3 freeze to list the local installed libraries.
use ./ENV/pip-3.3 install packagename to install at the local environment.
use ./ENV/python3.3 pythonfile.py to run your python script.
Here is my way to solve this problem at ubuntu 12.04:
sudo apt-get install build-essential libncursesw5-dev libssl-dev libgdbm-dev libc6-dev libsqlite3-dev tk-dev
Then install the python3 from source code:
wget https://www.python.org/ftp/python/3.4.0/Python-3.4.0.tar.xz
tar xvf Python-3.4.0.tar.xz
cd Python-3.4.0
./configure
make
make test
sudo make install
When you finished installing all of them, pip3 will get installed automatically.
This is what I did on OS X Mavericks to get this to work.
Firstly, have brew installed
Install python 3.4
brew install python3
Then I get the latest version of distribute:
wget https://pypi.python.org/packages/source/d/distribute/distribute-0.7.3.zip#md5=c6c59594a7b180af57af8a0cc0cf5b4a
unzip distribute-0.7.3.zip
cd distribute-0.7.3
sudo setup.py install
sudo easy_install-3.4 pip
sudo pip3.4 install virtualenv
sudo pip3.4 install virtualenvwrapper
mkvirtualenv py3
python --version
Python 3.4.1
I hope this helps.
pip is installed together when you install Python. You can use
sudo pip install (module)
or
python3 -m pip install (module).
Please follow below steps to install python 3 with pip:
Step 1 : Install Python from download here
Step 2 : you’ll need to download get-pip.py
Step 3 : After download get-pip.py , open your commant prompt and go to directory where your get-pip.py file saved .
Step 4 : Enter command python get-pip.py in cmd.
Step 5 : Pip installed successfully , Verify pip installation by type command in cmd pip --version
What’s New In Python 3.4
...
pip should always be available
...
By default, the commands pipX and pipX.Y will be installed on all platforms (where X.Y stands for the version of the Python installation), along with the pip Python package and its dependencies.
https://docs.python.org/3/whatsnew/3.4.html#whatsnew-pep-453
so if you have python 3.4 installed, you can just: sudo pip3 install xxx
For python3 try this:
wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | python
The good thing is that It will also detect what version of python you have (even if it's an environment of python in your custom location).
After this you can proceed normally with (for example)
pip install numpy
source:
https://pypi.python.org/pypi/setuptools/1.1.6#upgrading-from-setuptools-0-6
Assuming you are in a highly restricted computer env (such as myself) without root access or ability to install packages...
I had never setup a fresh/standalone/raw/non-root instance of Python+virtualenv before this post. I had do quite a bit of Googling to make this work.
Decide if you are using python (python2) or python3 and set your PATH correctly. (I am strictly a python3 user.) All commands below can substitute python3 for python if you are python2 user.
wget https://pypi.python.org/packages/source/v/virtualenv/virtualenv-x.y.z.tar.gz
tar -xzvf virtualenv-x.y.z.tar.gz
python3 virtualenv-x.y.z/virtualenv.py --python $(which python3) /path/to/new/virtualenv
source /path/to/new/virtualenv/bin/activate
Assumes you are using a Bourne-compatible shell, e.g., bash
Brilliantly, this virtualenv package includes a standalone version of pip and setuptools that are auto-magically installed into each new virtualenv. This solves the chicken and egg problem.
You may want to create an alias (or update your ~/.bashrc, etc.) for this final command to activate the python virtualenv during each login. It can be a pain to remember all these paths and commands.
Check your version of python now: which python3 should give: /path/to/new/virtualenv/bin/python3
Check pip is also available in the virtualenv via which pip... should give: /path/to/new/virtualenv/bin/pip
Then... pip, pip, pip!
Final tip to newbie Pythoneers: You don't think you need virtualenv when you start, but you will be happy to have it later. Helps with "what if" installation / upgrade scenarios for open source / shared packages.
Ref: https://virtualenv.pypa.io/en/latest/installation.html
To install pip, securely download get-pip.py.
Then run the following:
python get-pip.py
Be cautious if you're using a Python install that's managed by your
operating system or another package manager. get-pip.py does not
coordinate with those tools, and may leave your system in an
inconsistent state.
Refer: PIP Installation
And for Windows 8.1/10 OS Users just open cmd (command prompt)
write this : C:\Users\%USERNAME%\AppData\Local\Programs\Python\Python36-32\Scripts
then
just write this : pip3 install {name of package}
Hint: the location of folder Python36-32 may get different for new python 3.x versions
If you used the command "python get-pip.py", you should have the 'pip' function for Python3. However, 'pip' for Python2 might still be present. In my case I uninstalled 'pip', which removed it from Python2.
After that I ran "python get-pip.py" again. (Make sure that 'get-pip.py' is saved in the same folder as Python3.) The final step was to add the directory with 'pip' command to $PATH. That solved it for me.
=>Easy way to install Python any version on Ubuntu 18.04 or Ubuntu 20.04 follow these steps:-
Step 1: Update Local Repositories:-
sudo apt update
Step 2: Install Supporting Software:-
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
Step3: Create directory on your home directory To download the newest release of Python Source Code, navigate to the /python-source-files directory and use the wget command:-
mkdir python-source-files
Step 4: Download the Latest Version of Python Source Code:-
wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz
"you can change python version by just modifies this:-"3.7.5" with the version you want example:-"3.5.2"
Step 5: Extract Compressed Files:-
tar –xf Python-3.7.5.tgz
or
tar xvzf Python-3.7.5.tgz
Step 6: Test System and Optimize Python:-
cd python-3.7.5 or your version of python.
Step 7: Now configure(Using the ––optimization option speeds code execution by 10-20%.):-
./configure ––enable–optimizations
OR you can also do this also if you facing ssl error:-
./configure --with-openssl
Step 8: Install a Second Instance of Python:-
sudo make altinstall
"It is recommended that you use the altinstall method. Your Ubuntu system may have software packages dependent on Python 2.x.
OR
If you want to Overwrite Default Python Installation/version:-
sudo make install"
Step 9:Now check Python Version:-
python3 ––version
Step 10: To install pip for python3 just go with this command:-
sudo apt-get install python3-pip

How can I install a legacy PIP version with python 2.6.6 or python 2.7.5?

I'm struggling to install the python pip module on my centOS server which is running on python2.6.6(centOS 6) or python 2.7.5(CentOS7). Due to some reasons I'm not able to upgrade the python version to 3 or later. So in the case, how can I install a legacy PIP version line pip 20 with my python2.6 or python 2.7 platform?
Thanks.
You can use get-pip.py for 2.7. Here's an example in a centos:7 Docker container:
$ python -V
Python 2.7.5
$ curl -fsSL -O https://bootstrap.pypa.io/pip/2.7/get-pip.py
$ python get-pip.py --no-python-version-warning && rm -f get-pip.py
$ python -m pip --version
pip 20.3.4 from /usr/lib/python2.7/site-packages/pip (python 2.7)
Docs: https://pip.pypa.io/en/stable/installing/#installing-with-get-pip-py. (Though admittedly, they don't go out of their way to point out the presence of the 2.6/2.7 branches, given that Python 2 is prominently EOL.)
If you have Python 2, you most likely have pip. Try python2 -m pip install foobar.
Turns out that in CentOS7 pip is not available in distro repos by default. You need to yum install epel-release to enable the EPEL repo, which in turn contains pip: yum install python-pip.
So do this: (as root/using sudo)
yum install epel-release
yum makecache
yum install python-pip

How do I install pip3 for Python3 without root privileges on CentOS 7.6? [duplicate]

I want to install pip. It should support Python 3, but it requires setuptools, which is available only for Python 2.
How can I install pip with Python 3?
edit: Manual installation and use of setuptools is not the standard process anymore.
If you're running Python 2.7.9+ or Python 3.4+
Congrats, you should already have pip installed. If you do not, read onward.
If you're running a Unix-like System
You can usually install the package for pip through your package manager if your version of Python is older than 2.7.9 or 3.4, or if your system did not include it for whatever reason.
Instructions for some of the more common distros follow.
Installing on Debian (Wheezy and newer) and Ubuntu (Trusty Tahr and newer) for Python 2.x
Run the following command from a terminal:
sudo apt-get install python-pip
Installing on Debian (Wheezy and newer) and Ubuntu (Trusty Tahr and newer) for Python 3.x
Run the following command from a terminal:
sudo apt-get install python3-pip
Note:
On a fresh Debian/Ubuntu install, the package may not be found until you do:
sudo apt-get update
Installing pip on CentOS 7 for Python 2.x
On CentOS 7, you have to install setup tools first, and then use that to install pip, as there is no direct package for it.
sudo yum install python-setuptools
sudo easy_install pip
Installing pip on CentOS 7 for Python 3.x
Assuming you installed Python 3.4 from EPEL, you can install Python 3's setup tools and use it to install pip.
# First command requires you to have enabled EPEL for CentOS7
sudo yum install python34-setuptools
sudo easy_install pip
If your Unix/Linux distro doesn't have it in package repos
Install using the manual way detailed below.
The manual way
If you want to do it the manual way, the now-recommended method is to install using the get-pip.py script from pip's installation instructions.
Install pip
To install pip, securely download get-pip.py
Then run the following (which may require administrator access):
python get-pip.py
If setuptools is not already installed, get-pip.py will install setuptools for you.
I was able to install pip for python 3 on Ubuntu just by running sudo apt-get install python3-pip.
Python 3.4+ and Python 2.7.9+
Good news! Python 3.4 (released March 2014) ships with Pip. This is the best feature of any Python release. It makes the community's wealth of libraries accessible to everyone. Newbies are no longer excluded by the prohibitive difficulty of setup. In shipping with a package manager, Python joins Ruby, Nodejs, Haskell, Perl, Go--almost every other contemporary language with a majority open-source community. Thank you Python.
Of course, that doesn't mean Python packaging is problem solved. The experience remains frustrating. I discuss this at Does Python have a package/module management system?
Alas for everyone using an earlier Python. Manual instructions follow.
Python ≤ 2.7.8 and Python ≤ 3.3
Follow my detailed instructions at https://stackoverflow.com/a/12476379/284795 . Essentially
Official instructions
Per https://pip.pypa.io/en/stable/installing.html
Download get-pip.py, being careful to save it as a .py file rather than .txt. Then, run it from the command prompt.
python get-pip.py
You possibly need an administrator command prompt to do this. Follow http://technet.microsoft.com/en-us/library/cc947813(v=ws.10).aspx
For me, this installed Pip at C:\Python27\Scripts\pip.exe. Find pip.exe on your computer, then add its folder (eg. C:\Python27\Scripts) to your path (Start / Edit environment variables). Now you should be able to run pip from the command line. Try installing a package:
pip install httpie
There you go (hopefully)!
if you're using python 3.4+
just type:
python3 -m pip
For Ubuntu 12.04 or older,
sudo apt-get install python3-pip
won't work. Instead, use:
sudo apt-get install python3-setuptools ca-certificates
sudo easy_install3 pip
Update 2015-01-20:
As per https://pip.pypa.io/en/latest/installing.html the current way is:
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
I think that should work for any version
Original Answer:
wget http://python-distribute.org/distribute_setup.py
python distribute_setup.py
easy_install pip
Single Python in system
To install packages in Python always follow these steps:
If the package is for python 2.x: sudo python -m pip install [package]
If the package is for python 3.x: sudo python3 -m pip install [package]
Note: This is assuming no alias is set for python
Through this method, there will be no confusion regarding which python version is receiving the package.
Multiple Pythons/Virtual Envs
Say you have python3 ↔ python3.6 and python3.7 ↔ python3.7
To install for python3.6: sudo python3 -m pip install [package]
To instal for python3.7: sudo python3.7 -m pip install [package]
This is essentially the same method as shown previously.
Note 1
How to find which python? Do one of the following:
~ » python3 -c "import sys; print(sys.version)"
3.9.5 (default, Nov 18 2021, 16:00:48)
your python3 command spawns:
~ » python3
Python 3.9.5 (default, Nov 18 2021, 16:00:48)
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Notice python 3.9.5 in the second line.
or say you are using virtual env and see where your python points to:
» which python
/home/ganesh/os/np-test/bin/python
Note 2
Change what python3 or python points to: https://askubuntu.com/questions/320996/how-to-make-python-program-command-execute-python-3
python3 -m ensurepip
I'm not sure when exactly this was introduced, but it's installed pip3 for me when it didn't already exist.
Older version of Homebrew
If you are on macOS, use homebrew.
brew install python3 # this installs python only
brew postinstall python3 # this command installs pip
Also note that you should check the console if the install finished successfully. Sometimes it doesn't (e.g. an error due to ownership), but people simply overlook the log.
UPDATED - Homebrew version after 1.5
According to the official Homebrew page:
On 1st March 2018 the python formula will be upgraded to Python 3.x and a python#2 formula will be added for installing Python 2.7 (although this will be keg-only so neither python nor python2 will be added to the PATH by default without a manual brew link --force). We will maintain python2, python3 and python#3 aliases.
So to install Python 3, run the following command:
brew install python3
Then, the pip is installed automatically, and you can install any package by pip install <package>.
If your Linux distro came with Python already installed, you should be able to install PIP using your system’s package manager. This is preferable since system-installed versions of Python do not play nicely with the get-pip.py script used on Windows and Mac.
Advanced Package Tool (Python 2.x)
sudo apt-get install python-pip
Advanced Package Tool (Python 3.x)
sudo apt-get install python3-pip
pacman Package Manager (Python 2.x)
sudo pacman -S python2-pip
pacman Package Manager (Python 3.x)
sudo pacman -S python-pip
Yum Package Manager (Python 2.x)
sudo yum upgrade python-setuptools
sudo yum install python-pip python-wheel
Yum Package Manager (Python 3.x)
sudo yum install python3 python3-wheel
Dandified Yum (Python 2.x)
sudo dnf upgrade python-setuptools
sudo dnf install python-pip python-wheel
Dandified Yum (Python 3.x)
sudo dnf install python3 python3-wheel
Zypper Package Manager (Python 2.x)
sudo zypper install python-pip python-setuptools python-wheel
Zypper Package Manager (Python 3.x)
sudo zypper install python3-pip python3-setuptools python3-wheel
This is the one-liner I copy-and-paste:
curl https://bootstrap.pypa.io/get-pip.py | python3
Alternate:
curl -L get-pip.io | python3
From Installing with get-pip.py:
To install pip, securely download get-pip.py by following this link:
get-pip.py. Alternatively, use
curl:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Then run the following command in the folder where you have downloaded
get-pip.py:
python get-pip.py
Warning: Be cautious if you are using a Python install that is managed
by your operating system or another package manager. get-pip.py does
not coordinate with those tools, and may leave your system in an
inconsistent state.
If you use several different versions of python try using virtualenv http://www.virtualenv.org/en/latest/virtualenv.html#installation
With the advantage of pip for each local environment.
Then install a local environment in the current directory by:
virtualenv -p /usr/local/bin/python3.3 ENV --verbose
Note that you specify the path to a python binary you have installed on your system.
Then there are now an local pythonenvironment in that folder. ./ENV
Now there should be ./ENV/pip-3.3
use
./ENV/pip-3.3 freeze to list the local installed libraries.
use ./ENV/pip-3.3 install packagename to install at the local environment.
use ./ENV/python3.3 pythonfile.py to run your python script.
Here is my way to solve this problem at ubuntu 12.04:
sudo apt-get install build-essential libncursesw5-dev libssl-dev libgdbm-dev libc6-dev libsqlite3-dev tk-dev
Then install the python3 from source code:
wget https://www.python.org/ftp/python/3.4.0/Python-3.4.0.tar.xz
tar xvf Python-3.4.0.tar.xz
cd Python-3.4.0
./configure
make
make test
sudo make install
When you finished installing all of them, pip3 will get installed automatically.
This is what I did on OS X Mavericks to get this to work.
Firstly, have brew installed
Install python 3.4
brew install python3
Then I get the latest version of distribute:
wget https://pypi.python.org/packages/source/d/distribute/distribute-0.7.3.zip#md5=c6c59594a7b180af57af8a0cc0cf5b4a
unzip distribute-0.7.3.zip
cd distribute-0.7.3
sudo setup.py install
sudo easy_install-3.4 pip
sudo pip3.4 install virtualenv
sudo pip3.4 install virtualenvwrapper
mkvirtualenv py3
python --version
Python 3.4.1
I hope this helps.
pip is installed together when you install Python. You can use
sudo pip install (module)
or
python3 -m pip install (module).
Please follow below steps to install python 3 with pip:
Step 1 : Install Python from download here
Step 2 : you’ll need to download get-pip.py
Step 3 : After download get-pip.py , open your commant prompt and go to directory where your get-pip.py file saved .
Step 4 : Enter command python get-pip.py in cmd.
Step 5 : Pip installed successfully , Verify pip installation by type command in cmd pip --version
What’s New In Python 3.4
...
pip should always be available
...
By default, the commands pipX and pipX.Y will be installed on all platforms (where X.Y stands for the version of the Python installation), along with the pip Python package and its dependencies.
https://docs.python.org/3/whatsnew/3.4.html#whatsnew-pep-453
so if you have python 3.4 installed, you can just: sudo pip3 install xxx
For python3 try this:
wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | python
The good thing is that It will also detect what version of python you have (even if it's an environment of python in your custom location).
After this you can proceed normally with (for example)
pip install numpy
source:
https://pypi.python.org/pypi/setuptools/1.1.6#upgrading-from-setuptools-0-6
Assuming you are in a highly restricted computer env (such as myself) without root access or ability to install packages...
I had never setup a fresh/standalone/raw/non-root instance of Python+virtualenv before this post. I had do quite a bit of Googling to make this work.
Decide if you are using python (python2) or python3 and set your PATH correctly. (I am strictly a python3 user.) All commands below can substitute python3 for python if you are python2 user.
wget https://pypi.python.org/packages/source/v/virtualenv/virtualenv-x.y.z.tar.gz
tar -xzvf virtualenv-x.y.z.tar.gz
python3 virtualenv-x.y.z/virtualenv.py --python $(which python3) /path/to/new/virtualenv
source /path/to/new/virtualenv/bin/activate
Assumes you are using a Bourne-compatible shell, e.g., bash
Brilliantly, this virtualenv package includes a standalone version of pip and setuptools that are auto-magically installed into each new virtualenv. This solves the chicken and egg problem.
You may want to create an alias (or update your ~/.bashrc, etc.) for this final command to activate the python virtualenv during each login. It can be a pain to remember all these paths and commands.
Check your version of python now: which python3 should give: /path/to/new/virtualenv/bin/python3
Check pip is also available in the virtualenv via which pip... should give: /path/to/new/virtualenv/bin/pip
Then... pip, pip, pip!
Final tip to newbie Pythoneers: You don't think you need virtualenv when you start, but you will be happy to have it later. Helps with "what if" installation / upgrade scenarios for open source / shared packages.
Ref: https://virtualenv.pypa.io/en/latest/installation.html
To install pip, securely download get-pip.py.
Then run the following:
python get-pip.py
Be cautious if you're using a Python install that's managed by your
operating system or another package manager. get-pip.py does not
coordinate with those tools, and may leave your system in an
inconsistent state.
Refer: PIP Installation
And for Windows 8.1/10 OS Users just open cmd (command prompt)
write this : C:\Users\%USERNAME%\AppData\Local\Programs\Python\Python36-32\Scripts
then
just write this : pip3 install {name of package}
Hint: the location of folder Python36-32 may get different for new python 3.x versions
If you used the command "python get-pip.py", you should have the 'pip' function for Python3. However, 'pip' for Python2 might still be present. In my case I uninstalled 'pip', which removed it from Python2.
After that I ran "python get-pip.py" again. (Make sure that 'get-pip.py' is saved in the same folder as Python3.) The final step was to add the directory with 'pip' command to $PATH. That solved it for me.
=>Easy way to install Python any version on Ubuntu 18.04 or Ubuntu 20.04 follow these steps:-
Step 1: Update Local Repositories:-
sudo apt update
Step 2: Install Supporting Software:-
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
Step3: Create directory on your home directory To download the newest release of Python Source Code, navigate to the /python-source-files directory and use the wget command:-
mkdir python-source-files
Step 4: Download the Latest Version of Python Source Code:-
wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz
"you can change python version by just modifies this:-"3.7.5" with the version you want example:-"3.5.2"
Step 5: Extract Compressed Files:-
tar –xf Python-3.7.5.tgz
or
tar xvzf Python-3.7.5.tgz
Step 6: Test System and Optimize Python:-
cd python-3.7.5 or your version of python.
Step 7: Now configure(Using the ––optimization option speeds code execution by 10-20%.):-
./configure ––enable–optimizations
OR you can also do this also if you facing ssl error:-
./configure --with-openssl
Step 8: Install a Second Instance of Python:-
sudo make altinstall
"It is recommended that you use the altinstall method. Your Ubuntu system may have software packages dependent on Python 2.x.
OR
If you want to Overwrite Default Python Installation/version:-
sudo make install"
Step 9:Now check Python Version:-
python3 ––version
Step 10: To install pip for python3 just go with this command:-
sudo apt-get install python3-pip

Categories

Resources