About
RSS

Bit Focus


Troubleshooting : Upgrade pip3 in Ubuntu 16.04

Generally this post is about to setup a Python3 environment on Ubuntu 16.04. However since there seems a problem in pip so let me name it in the title directly.

I started with a fresh new Ubuntu 16.04 droplet at DigitalOcean and have run these commands.

(As non-root with sudo)

Code Snippet 0-0

$ sudo apt-get update
$ sudo apt-get install python3-pip -y
$ sudo pip3 install -U pip

So pip 10 is installed and things seem fine until here. However when I attempt to run pip3, it crashes with an unclear Python stacktrace.

Code Snippet 0-1

$ pip3 --version

Traceback (most recent call last):
  File "/usr/bin/pip3", line 9, in <module>
    from pip import main
ImportError: cannot import name 'main'

It seems that when apt-installed pip upgrades a pypi pip, the pypi pip will be broken and won't work. And the idea is not to use the system-wide pip but to use a venv pip instead.

So the solution is like this.

Code Snippet 0-2

$ sudo apt-get install python3-venv
$ python3 -m venv $HOME/.venv # or any directory you like
$ export PATH=$HOME/.venv/bin:$PATH

Then the pip in the virtualenv will work.

Code Snippet 0-3

$ which python
/home_directory/.venv/bin/python
$ python --version
python 3.5.2
$ which pip
/home_directory/.venv/bin/pip

Now upgrade pip with itself.

Code Snippet 0-4

$ pip install -U pip
...
$ pip --version
pip 10.0.1 from /home_direcotry/.venv/lib/python3.5/site-packages/pip (python 3.5)

Also, you can add export PATH=$HOME/.venv:$PATH to your .bashrc or .zshrc or anything like that.

Permanent Link: /p/6 Load full text

Post tags:

 Python
 Ubuntu
 Installation


. Back to Bit Focus
NijiPress - Copyright (C) Neuron Teckid @ Bit Focus
About this site