Python does not import correctly after upgrading to 14.04

I cannot import import modules from the standard library with c extensions. This happened after I upgraded to Ubuntu 14.04 from 12.04. I tried reinstalling python, python-dev, but that didn't help. I noticed other people with similar posts, but they all use virtualenv, while I don't use all of this.

Python 2.7.3 (default, Aug 1 2012, 05:16:07) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import pickle, email, json, readline, socket, turtle >>> import ctypes Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/ctypes/__init__.py", line 10, in <module> from _ctypes import Union, Structure, Array ImportError: No module named _ctypes >>> import io Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/io.py", line 51, in <module> import _io ImportError: No module named _io >>> import datetime Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named datetime 
+1
python ubuntu
source share
5 answers

from which -a python we see that the two python 2 installations in /usr/local/lib/python and /usr/bin/python/ , so removing /usr/local/lib/python will sort the problem.

+3
source share

If you are running virtualenv, it may have broken during the upgrade. You can repair it just by doing

 virtualenv /PATH/TO/EXISTING/ENVIRONMENT 

or

 virtualenv --system-site-packages /PATH/TO/EXISTING/ENVIRONMENT 
+1
source share

Perhaps your paths are incorrectly configured.

Try to see:

 import sys sys.path 

perhaps the python path does not exist and then does not import the modules.

If not there, add the path as a new item in the list.

 sys.path.append(new path) 

I hope this helps

0
source share

Based on your comment that which python returns /usr/local/lib/python , it looks like you have a local Python installation that is different from your distribution installation. Distribution packages are never installed in /usr/local on Ubuntu. Mixing custom Python with your distribution libraries (as the /usr/lib paths indicate in your errors) can lead to many problems.

I would recommend removing Python installed in /usr/local/lib (which is an odd place to install the binary), or removing it from your PATH so that you can access your distribution installed on Python.

0
source share

Without a module named _ctypes Error, you can try the following:

apt-get install libffi-dev

Hope this helps.

0
source share

All Articles