Can't load Python modules installed via pip from site-packages directory

PythonMacosBashModuleEvernote

Python Problem Overview


I am trying to install and use the Evernote module (https://github.com/evernote/evernote-sdk-python) . I ran pip install evernote and it says that the installation worked.

I can confirm that the evernote module exists in /usr/local/lib/python2.7/site-packages. However, when I try to run python -c "import evernote" I get the following error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named evernote

This is the contents of my .bash-profile:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

# Setting PATH for Python 3.3
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.3/bin:${PATH}"
export PATH
export PATH=$PATH:/usr/local/bin/

I am having this same problem with other modules installed with pip. Help?

EDIT: I am a super newbie and have not edited that .bash-profile file.

EDIT: python -c 'import sys; print "\n".join(sys.path)' Outputs the following:

/Library/Python/2.7/site-packages/setuptools-1.3.2-py2.7.egg
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC
/Library/Python/2.7/site-packages

EDIT: I seemed to have made progress towards a solution by adding export PYTHONPATH=“/usr/local/lib/python2.7/site-packages” to my .bash_profile file. However, now when I run python -c 'from evernote.api.client import EvernoteClient' it tries to import oauth2, which fails with the same error. The ouath2 module is present in the module directory.

Python Solutions


Solution 1 - Python

/usr/bin/python is the executable for the python that comes with OS X. /usr/local/lib is a location for user-installed programs only, possibly from Python.org or Homebrew. So you're mixing different Python installs, and changing the python path is only a partial workaround for different packages being installed for different installations.

In order to make sure you use the pip associated with a particular python, you can run python -m pip install <pkg>, or go look at what the pip on your path is, or is symlinked to.

Solution 2 - Python

I figured it out! I added this line:

export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages

to my .bash_profile and now I can import modules stored in that directory. Thanks for everyone who answered.

Solution 3 - Python

I faced similar problem,its related to /usr/local/lib/python2.7/site-packages had no read or write permission for group and other, and they were owned by root. This means that only the root user could access them.

Try this:

$ sudo chmod -R go+rX /usr/local/lib/python2.7/site-packages

Solution 4 - Python

None of this helped me with my similar problem. Instead, I had to fix the newly installed files permissions to be able to import. This is usually an obvious thing, but not so much when you use sudo when installing module/packages.

Solution 5 - Python

Simply just type in terminal:

sudo pip install pillow

and type import (whatever you like) or type from (whatever you like) import (whatever you like).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionChase McCoyView Question on Stackoverflow
Solution 1 - PythonJason SView Answer on Stackoverflow
Solution 2 - PythonChase McCoyView Answer on Stackoverflow
Solution 3 - Pythonprarit lambaView Answer on Stackoverflow
Solution 4 - PythoncnaakView Answer on Stackoverflow
Solution 5 - PythonamrView Answer on Stackoverflow