This is the intended behavior. The rationale for this is that you can continue to use your old installed modules, even though you are now using the new homeprewed Python.
Now this has some disadvantages, for example, some libraries, such as numpy, will not work in different versions of Python, so if you installed numpy, it would be imported from the old site-packages and would not work.
There are at least two ways to modify sys.path :
Use .pth file:
Python will select this from some of the built-in locations (for example: ~ / Library / Python / 2.7 / lib / python / site-packages / homebrew.pth). This adds to sys.path , which is not perfect, but has the advantage of not being selected by Python 3. This is currently the recommended method . You can achieve this with:
echo "$(brew --prefix)/lib/python2.7/site-packages" > ~/Library/Python/2.7/lib/python/site-packages/homebrew.pth
Install PYTHONPATH :
This is added to sys.path , it has a flaw that is global for all versions of python, so it is not recommended if you intend to use different versions of python. You can do this by adding to your .bash_profile :
export PYTHONPATH=`brew --prefix`/lib/python2.7/site-packages:$PYTHONPATH
I personally used option 2 with homebrew-python (now I use and recommend Anaconda). My reasons were that I was not interested in system Python or Python 3 then.
elyase
source share