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

若如初见. 提交于 2019-11-26 18:33:47

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

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.

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

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.

amr

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!