0

I have an Ubuntu 16.04 machine that has multiple python 3 installations at /python/ and needs to be able to switch between them at will. One of these versions is Python 3.3, and pip didn't come pre-installed until Python 3.4.x, so I want to install pip into this python installation. I don't want to use distro packages because it needs to be actually integrated into the /python/python33 installation, I'm having trouble managing this:

get-pip.py tries to uninstall the version of pip at /usr/bin:

$ /tmp/get-pip.py --prefix /python/python33
Collecting pip
  Using cached pip-9.0.1-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 8.1.2
    Uninstalling pip-8.1.2:
Exception:
Traceback (most recent call last):
  File "/tmp/tmpdgdWPZ/pip.zip/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/tmp/tmpdgdWPZ/pip.zip/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/tmp/tmpdgdWPZ/pip.zip/pip/req/req_set.py", line 778, in install
    requirement.uninstall(auto_confirm=True)
  File "/tmp/tmpdgdWPZ/pip.zip/pip/req/req_install.py", line 754, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "/tmp/tmpdgdWPZ/pip.zip/pip/req/req_uninstall.py", line 115, in remove
    renames(path, new_path)
  File "/tmp/tmpdgdWPZ/pip.zip/pip/utils/__init__.py", line 267, in renames
    shutil.move(old, new)
  File "/usr/lib/python2.7/shutil.py", line 303, in move
    os.unlink(src)
OSError: [Errno 13] Permission denied: '/usr/bin/pip'
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

If I add --ignore-installed, it doesn't error out but is still looking at the version of pip at /usr/bin (the old 8.1.2 one that it's complaining about):

$ /tmp/get-pip.py --ignore-installed --prefix /python/python33
Collecting pip
  Using cached pip-9.0.1-py2.py3-none-any.whl
Installing collected packages: pip
Successfully installed pip-9.0.1
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

easy_install doesn't work either:

$ export PYTHONPATH="$PYTHONPATH:/python/python33/"; /usr/bin/easy_install --prefix /python/python33 pip
TEST FAILED: /python/python33/lib/python2.7/site-packages does NOT support .pth files
error: bad install directory or PYTHONPATH

You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from.  The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    /python/python33/lib/python2.7/site-packages

and your PYTHONPATH environment variable currently contains:

    '/pyqt/sip-4.13.1/site-packages:/pyqt/site-packages:/python/python33/'

Here are some of your options for correcting the problem:

* You can choose a different installation directory, i.e., one that is
  on PYTHONPATH or supports .pth files

* You can add the installation directory to the PYTHONPATH environment
  variable.  (It must then also be on PYTHONPATH whenever you run
  Python and want to use the package(s) you are installing.)

* You can set up the installation directory to support ".pth" files by
  using one of the approaches described here:

  https://pythonhosted.org/setuptools/easy_install.html#custom-installation-locations

Please make the appropriate changes for your system and try again.

And why is it trying to install into /python/python33/lib/python2.7/site-packages? Is this the python 2 version of pip or something?

I've read a lot of related answers here on SO, but none of them have helped so far.

iLikeDirt
  • 606
  • 5
  • 17

1 Answers1

0

I have Python 3.5.2 an 3.6.3 installed on a 16.04 Ubuntu Box.

3.5.2 is the system installed version at /usr/bin Symlinks for python3 and python3.5 point to this version

3.6.3 is installed at /usr/local/bin python3.6 points to this version

For me the following works:

wget https://bootstrap.pypa.io/get-pip.py
python3.6 get-pip.py
mkdir /home/ubuntu/myproj/venv
python3.6 -m venv /home/ubuntu/myproj/venv
#Activate the venv
source /home/ubuntu/myproj/venv/bin/activate

python3 now points to 3.6 inside my virtual environment.

How did you install Python 3.6 on 16.04. I had a world of hurt getting it to not break things. In the end I built from source. See this gist for details. This question explains why. And this blog post gave me the solution.

WombatPM
  • 2,561
  • 2
  • 22
  • 22
  • have you tried [this ppa](https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa)? – georgexsh Dec 12 '17 at 22:17
  • Yes, and it works fine for python 3.6 The problem is that 16.04 needs python 3.5 for things like apt-get to work at a system level. – WombatPM Dec 23 '17 at 03:31
  • install python36 from deadsnake ppa doesn’t’ shadow system pyhton, you have problem with it? – georgexsh Dec 23 '17 at 03:35
  • Not now. I realized I was giving python 3.6 priority over 3.5 when called via python3. Of course learning to build from source is always an adventure. – WombatPM Dec 29 '17 at 15:40