64

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.

7
  • I can confirm that I am using Python 2.7.5. Aug 13, 2014 at 0:46
  • Try this line to check if Evernote SDK is installed python -c 'from evernote.api.client import EvernoteClient' Aug 13, 2014 at 0:50
  • python --version gives my 2.7.5. I am not sure how that comment got added to the .bash-profile. I have Python 3 installed, but I have to use python3 in order to use it. Aug 13, 2014 at 0:51
  • That line is what I was using, and it does not work. I get ImportError: No module named evernote.api.client Aug 13, 2014 at 0:51
  • What does type python output? what about python -c 'import sys; print "\n".join(sys.path)'? Aug 13, 2014 at 1:24

5 Answers 5

91

/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.

5
  • 19
    python -m pip install <pkg> seems to work beautifully.
    – Piper
    Feb 16, 2015 at 4:03
  • 2
    What does -m do? Mar 10, 2016 at 21:18
  • 2
    @acollection_ : -m is from library Module Jul 20, 2016 at 17:57
  • 3
    python -m pip install <pkg> is the best workaround. Alternately, you can also do this: -> import sys -> sys.path.append("/usr/local/lib/python2.7/site-packages") Adding these two lines to your python script or typing them in the interpreter works the same way. Jan 15, 2017 at 5:33
  • 1
    I get /usr/bin/python: No module named pip when I try to use this command.
    – annedroiid
    Jul 9, 2018 at 13:15
63

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.

3
  • I got the feeling that solved the whole python not working on mac EPIC. Thanx!
    – Macilias
    Jan 18, 2017 at 10:21
  • It's also common problem with python3. That solution also works with that May 23, 2017 at 13:41
  • This didn't work for me when pointing to Python3 site package folder Apr 5, 2021 at 7:15
6

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
4

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.

1
  • I also had to delete some .pyc files from one of my packages. I think they were created after I had made the package directory readable, but before I made the package subdirs readable. The error message I was receiving which led me to the .pyc file problem was: File "requests/__init__.py", line 97, in <module> from . import utils ImportError: cannot import name utils In my case, I think it was __init__.pyc which was the problem, but I removed all .pyc files to be sure. Lesson: Do chmod -R a+rX site-package-module-dir as described in @prarit-lamba's answer
    – Josh
    Feb 9, 2018 at 17:03
-5

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).

0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.