The Python Oracle

Unable to import a module that is definitely installed

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Book End

--

Chapters
00:00 Unable To Import A Module That Is Definitely Installed
00:41 Answer 1 Score 30
00:59 Accepted Answer Score 137
01:14 Answer 3 Score 33
01:57 Answer 4 Score 135
02:50 Thank you

--

Full question
https://stackoverflow.com/questions/1429...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #importerror #pythonmodule

#avk47



ACCEPTED ANSWER

Score 137


In my case, it is permission problem. The package was somehow installed with root rw permission only, other user just cannot rw to it!




ANSWER 2

Score 135


I had the same problem: script with import colorama was throwing an ImportError, but sudo pip install colorama was telling me "package already installed".

My fix: run pip without sudo: pip install colorama. Then pip agreed it needed to be installed, installed it, and my script ran.

Or even better, use python -m pip install <package>. The benefit of this is, since you are executing the specific version of python that you want the package in, pip will unequivocally install the package into the "right" python. Again, don't use sudo in this case... then you get the package in the right place, but possibly with (unwanted) root permissions.

My environment is Ubuntu 14.04 32-bit; I think I saw this before and after I activated my virtualenv.




ANSWER 3

Score 33


It's the python path problem.

In my case, I have python installed in:

/Library/Frameworks/Python.framework/Versions/2.6/bin/python,

and there is no site-packages directory within the python2.6.

The package(SOAPpy) I installed by pip is located

/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/

And site-package is not in the python path, all I did is add site-packages to PYTHONPATH permanently.

  1. Open up Terminal

  2. Type open .bash_profile

  3. In the text file that pops up, add this line at the end:

    export PYTHONPATH=$PYTHONPATH:/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/
    
  4. Save the file, restart the Terminal, and you're done




ANSWER 4

Score 30


The Python import mechanism works, really, so, either:

  1. Your PYTHONPATH is wrong,
  2. Your library is not installed where you think it is
  3. You have another library with the same name masking this one