2

I have CentOS7 installed. So python2.7 is natively installed under /usr/lib.

I want to switch to use python3 as my primary installation. So I downloaded python3.5x from the official site, and after installation its located under /usr/local/lib/. Even though I want to use python 3.x as my primary installation, I still must launch python with 'python3'. 'python' still launches python 2.7. Note: I perform install using 'make install', as opposed to 'make altinstall', as per README instructions.

If I use pip to install packages, they only get installed for python2.7. I've come across other posts, which suggest installing/using pip3. But I've been unable to figure out to get pip3 installed.

Here's the version of pip that I currently have installed:

# pip --version
pip 8.1.2 from /usr/lib/python2.7/site-packages/pip-8.1.2-py2.7.egg (python 2.7)

UPDATE:
It was indicated this question was a dup of this one: How to install pip with Python 3?

My question is NOT how to install pip. But rather how to get pip working with 2 installations of python (2.7 and 3.x). It seems pip works for installing packages for python2.7 (the native python installation in CentOS7), but I cannot seem to get it to install packages for python3.

Community
  • 1
  • 1
jersey bean
  • 3,321
  • 4
  • 28
  • 43
  • You should have pip3 along with python3 in your machine. Did you check pip3 --version command? – Wasi Ahmad Oct 28 '16 at 17:24
  • install and use pip3 – Tales Pádua Oct 28 '16 at 17:24
  • In your scripts, you can add this line "#!/usr/bin/python3" in the top to interpret your code with python3. You can also create virtual environment and assign python3 as interpreter there to work in python3. You should try virtual environment, it gives flexibility to use python version of your choice. – Wasi Ahmad Oct 28 '16 at 17:26
  • @WasiAhmad yes I checked for pip3 on my system (/usr/bin, /usr/local/bin/). Its doesn't not come installed with python3. I only have pip, pip2, and pip2.7. – jersey bean Nov 01 '16 at 23:53

2 Answers2

4

This stackoverflow post explains how to install pip for python3 in CentosOS7.

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
Community
  • 1
  • 1
bramwelt
  • 191
  • 1
  • 8
1

You can add the IUS repo and then install Python3 via yum. https://ius.io/GettingStarted/

However, linking python to python3 will break a lot of things on your system.

VPfB
  • 14,927
  • 6
  • 41
  • 75
  • thx. i found this link: http://www.codeghar.com/blog/install-latest-python-on-centos-7.html. He suggests using sudo yum install -y https://centos7.iuscommunity.org/ius-release.rpm. I believe you suggested the IUS community, so I believe your answer was correct. Then I was able to install python3 for the system python using: sudo yum install -y python35u python35u-libs python35u-devel python35u-pip. Now I have pip3. Thx! – jersey bean Nov 02 '16 at 05:16
  • is there any way to use Django 2.0 or later in Centos 7, as it requires python 3.x and as you said it is gonna break a lot of things in my system? – Siraj Alam May 12 '18 at 16:18
  • @Siraj. No, installing python3 will not break anything. I said linking python to python3 (executables i `/usr/bin` are meant) will break things. I think I wrote that in reaction to a comment which seems to be deleted in meantime. Anyway, let me repeat: if you normally install python3, you should be fine. – VPfB May 12 '18 at 18:44