No module named 'encodings' after upgrading to 16.04

Hi I upgraded my Ubuntu to 16.04 but whenever I try to run a Python program or pip install (both Python 2.7 or Python 3.5) I get the following error:

ImportError: No module named 'encodings'

Screenshot

14

2 Answers

From the comments, it looks like you were trying to use pip3 inside a virtualenv that is set up for Python 2. Note that running virtualenv venv creates a virtualenv named venv for Python 2 by default on Ubuntu if you don't specify the Python version explicitly.

In any case, if you want to create a virtualenv for Python 2, run:

virtualenv venv # create virtualenv named venv for Python 2

If you want to create a virtualenv for Python 3, run:

virtualenv venv -p python3 # create virtualenv named venv for Python 3

In both cases, after you have activated the virtualenv by running source venv/bin/activate, you just need to call pip to install Python packages; this still applies for a virtualenv created for Python 3 because pip already knows what Python version you are using, so don't call pip3.

I used dpkg -S <missing file> to figure out which package to reinstall...

Then I ran (example):

sudo apt install --reinstall libpython2.7-stdlib libpython2.7-minimal

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like