Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named _io in ubuntu 14.04

I just fresh installed ubuntu 14.04LTS and i am trying to use pip but i am getting the following traceback:

(nlmanagement)psychok7@Ultrabook:~/code/work/nlmanagement$ pip freeze
Traceback (most recent call last):
  File "/home/psychok7/code/work/venv/nlmanagement/bin/pip", line 9, in <module>
    load_entry_point('pip==1.1', 'console_scripts', 'pip')()
  File "/home/psychok7/code/work/venv/nlmanagement/local/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg/pkg_resources.py", line 337, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/home/psychok7/code/work/venv/nlmanagement/local/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg/pkg_resources.py", line 2279, in load_entry_point
    return ep.load()
  File "/home/psychok7/code/work/venv/nlmanagement/local/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg/pkg_resources.py", line 1989, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/home/psychok7/code/work/venv/nlmanagement/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/__init__.py", line 10, in <module>
    from pip.backwardcompat import walk_packages, console_to_str
  File "/home/psychok7/code/work/venv/nlmanagement/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/backwardcompat.py", line 77, in <module>
    from urllib2 import URLError, HTTPError
  File "/usr/lib/python2.7/urllib2.py", line 94, in <module>
    import httplib
  File "/usr/lib/python2.7/httplib.py", line 79, in <module>
    import mimetools
  File "/usr/lib/python2.7/mimetools.py", line 6, in <module>
    import tempfile
  File "/usr/lib/python2.7/tempfile.py", line 32, in <module>
    import io as _io
  File "/usr/lib/python2.7/io.py", line 51, in <module>
    import _io
ImportError: No module named _io

any ideas?? i have tried sudo apt-get install python3-pip and sudo apt-get install python-pip

like image 792
psychok7 Avatar asked Apr 19 '14 23:04

psychok7


4 Answers

I had the same problem. This happened in Ubuntu - 14.04 and Virtual environment's Python version - 2.7.3

After spending a day in debugging, posting my answer here, hope it helps for future visitors.

I found that io.py is invoking _io module. I think _io module is internal to the interpreter, so, just replacing the python binary in the environment alone with the newer version should fix.

(In my case, Cloudera Manager 5.x Agent's virtualenv on ubuntu 14.04 was using python interpreter 2.7.3, replaced it with 2.7.6.

echo "Using " && python2.7 --version
mv myenv/bin/python myenv/bin/python.bak;
cp `which python2.7` myenv/bin/python

When a new virtualenv is created, it uses updated python binary from the system. Hence, that explains the accepted answer in the thread.

like image 169
Thamme Gowda Avatar answered Nov 08 '22 23:11

Thamme Gowda


Your virtualenv became corrupt due to diffs in the Python system lib.

Best choice is to reinstall your virtualenv:

$ deactivate
$ rmvirtualenv nlmanagement
$ mkvirtualenv nlmanagement
$ pip install -r requirements.txt
like image 28
Yuval Adam Avatar answered Nov 08 '22 22:11

Yuval Adam


You don't need to delete the virtual environment.

Just follow these steps.

  1. Let's say your virtual environment name is "mydev" and you are using virtualenvwrapper, do

    cd $WORKON_HOME
    virtualenv mydev
    

    The above command just upgrades the link to the python executable without losing any package. Without virtualenvwrapper, $WORKON_HOME might not be defined; then you need to change to the parent directory of the virtualenv.

  2. outside virtualenv, if your pip is not working, then just

    easy_install pip
    

    will resolve the issue.

like image 21
Gomes Avatar answered Nov 08 '22 22:11

Gomes


After upgrading my ubuntu server to 14.04, I also have this kind of problem while executing pip

ImportError: No module named _io

Then I found out simply reinstall virtualenv can solve this issue!

sudo pip install virtualenv --upgrade

like image 3
kakashi Avatar answered Nov 08 '22 23:11

kakashi