7

CentOS 7 already has Python2.7.5 stock installed. I am doing an online course that requires Python3.x installed. So these are the following steps i took to install Python3.7.3.rc1 :

$cd /usr/src
$sudo wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3rc1.tgz
$sudo tar xzf Python-3.7.3rc1.tgz
$cd Python-3.7.3rc1
$sudo ./configure --enable-optimizations
$sudo make altinstall
$sudo rm /usr/src/Python-3.7.3rc1.tgz
$python3.7 --version
Python 3.7.3rc1

I followed these steps religiously from this link : https://tecadmin.net/install-python-3-7-on-centos/

During my course i was required to install pyperclip using pip. So i did :

$python3.7 -m pip install pyperclip
/usr/local/bin/python3.7: No module named pip

Please suggest a method to install pip for Python3.7.3rc1.

lycanthrope10100
  • 111
  • 1
  • 2
  • 12
  • Have you tried running the `pip` command directly, without `python` before it? Like: `pip install pyperclip`. – Ícaro Mar 15 '19 at 17:54
  • 1
    Yes, but the problem is that running pip directly uses Python2.7.5. So importing pyperclip in Python3.7.3rc1 gives error `ModuleNotFoundError: No module named 'pyperclip'` but works fine for Python2.7.5. – lycanthrope10100 Mar 15 '19 at 18:00
  • I see. How about running `pip3`? Does it show something to you? – Ícaro Mar 15 '19 at 18:01
  • No, `bash: pip3: command not found...`. – lycanthrope10100 Mar 15 '19 at 18:04
  • Think you've done a lot of work for a beginner unnecessarily. Try installing the python36 package that's the default supported python3.x series in centos 7 – Magnus Melwin Mar 15 '19 at 18:09
  • Possible duplicate of [Recommended way to install pip(3) on centos7](https://stackoverflow.com/questions/50408941/recommended-way-to-install-pip3-on-centos7) – hoefling Mar 17 '19 at 13:30
  • Notes for building python 3.7: it requires a recent version of OpenSSL that is not (and most probably will never be) available in CentOS 7. You would need to build OpenSSL and install it alongside the default one and then link python against it. Not something I'd recommend as there will be a lot of inconsistencies in the thrid-party python packages anyway (e.g. you'll need to build `cryptography` or `pyopenssl` from source with correct linking which is pretty much a PITA and the errors will be hard to trace). – hoefling Mar 17 '19 at 13:34
  • @hoefling Your comment suggests that OpenSSL is a requirement to build Python3.7.x and is certainly not preinstalled in CentOS7. However i was still able to build the Python3.7.3rc1 package without any problem and the IDLE was working fine as then. Later it became clear to me later that pip does not get sideloaded when i install the package manually. However importing the module worked just as fine if i copied the site-packages from another Python3.7.x machine with pip running manually to my current machine. But this just created a lot of extra steps for a simple task unnecessarily. – lycanthrope10100 Mar 17 '19 at 18:04
  • Yepp, just checked again, CentOS 7 includes OpenSSL 1.0.2k since Nov 18, so it's not an issue anymore. – hoefling Mar 17 '19 at 18:10

3 Answers3

6

You should have taken the default available python3, that is the python3.6 package in centos7 that would have been easier to setup rather than compile an unsupported version. Suggest you install the supported python3 package in centos

Try doing yum install python36 from repository

sudo yum install -y https://repo.ius.io/ius-release-el7.rpm

Update yum package

 sudo yum update

Install python36 along with pip

sudo yum install -y python36u python36u-libs python36u-devel python36u-pip

Below steps are for python3.7, suggest avoiding unsupported packages. Alternate Steps for pip setup for Centos You need to install pip for python3.7 series Step 1: First install the EPEL Repository

sudo yum install epel-release

Step 2: Installing pip

python37 -m pip

Step 3: Verify if pip was installed properly pip --version

If the command not found error shows up, try

python37 -m ensurepip
lycanthrope10100
  • 111
  • 1
  • 2
  • 12
Magnus Melwin
  • 1,509
  • 1
  • 21
  • 32
0

I also as you said "followed these steps religiously from this link: https://tecadmin.net/install-python-3-7-on-centos/."

It was not an option for me to install python3.6, as I explicitly needed 3.7. I was able to install using the following procedure:

# AFAIK, libffi-devel solved the "ModuleNotFoundError: No module named '_ctypes'" I had when I tried installing without it. 
yum install libffi-devel 

cd /usr/src
wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz
tar xzf Python-3.7.5.tgz
cd Python-3.7.5
./configure --enable-optimizations
make install  # Or: make altinstall
python3 -V
pip3 --version
rm -f /usr/src/Python-3.7.5.tgz

What I changed from the referenced article is the version (3.7.5 instead of 3.7.4) and in addition installed "libffi-devel". It could be that this one would have solved on 3.7.4 as well.

Yuval
  • 51
  • 8
-1

For CentOS 6 and 7 you can run this:

sudo yum install python37-setuptools sudo easy_install-3.7 pip

Edit: You should then be able to install using pip3 install <package>

bbruno5
  • 111
  • 1
  • 4
  • 9