0

I have spent a few hours trying to solve this problem but didn't manage yet. I figure my question is a bit specific to my own mac configuration and I need a more detailed instruction.

So my problem is that I installed Ruby using home-brew, for some reason, this installation changed my default python site-package directory. Before I have Ruby, my terminal python will automatically call the site-package from the path '/Users/xxxxxx/canopy/lib/python2.7/site-packages'. However, it now will use '/Library/Python/2.7/site-packages'. I tried three different ways to solve this issue but all failed:

1 use Canopy Terminal like this Set Canopy Preference, but this method point to another directory '/Applications/Canopy.app/appdata/canopy-1.5.2.2785.macosx-x86_64/Canopy.app/Contents/lib/python2.7/site-packages', which is not i want either.

2 change the bash_profile like this amend path, but by just putting the # in every line of the bash_profile, it still use directory '/Library/Python/2.7/site-packages'. Btw, my bash_profile and $PATH looks like this before: bash_profile before path before and looks like this bash_profile now path now

3 add the path '/Users/xxxxxx/canopy/lib/python2.7/site-packages' into sys.path, which look like this now:

enter image description here

But none of those worked. How can I make my terminal point to the path '/Users/xxxxxx/canopy/lib/python2.7/site-packages' now? Or ultimately, what should I do to clean up those different site-packages and use the one I only need?

Thank you for any help!

Community
  • 1
  • 1

2 Answers2

1

On a mac by default the path is /Library/Python/2.7/site-packages/foo.egg. Before doing anything, in terminal, start a new Python session and do

import sys
print sys.path

If the paths are of the form /Library/Python/2.7/site-packages/foo.egg, then just follow link

tl;dr

Basically add this to your bash_profile,

source [...] /activate
VIRTUAL_ENV_DISABLE_PROMPT=1 source [...] activate
Ankit Sultana
  • 417
  • 4
  • 14
  • Thanks @bk2dcradle. But I was not sure what you mean by "the paths are of the form /Library/Python/2.7/site-packages/foo.egg". Basically I want to change the path "/Library/Python/2.7/site-packages/" to the path "/Users/xxxxxx/canopy/lib/python2.7/site-packages", and I don't want to use the path "/Applications/Canopy.app/appdata/canopy-1.5.2.2785.macosx-x86_64/Canopy.app/Contents/lib/python2.7/site-packages". – user2855528 Jul 04 '15 at 21:30
  • 1
    Start a python session and do `import sys` `sys.prefix`, and tell me what you see – Ankit Sultana Jul 04 '15 at 21:36
  • I see : '/System/Library/Frameworks/Python.framework/Versions/2.7' – user2855528 Jul 04 '15 at 21:40
  • 1
    To change the path from the one you mentioned for the current session, do this, `import sys`, `sys.path.insert(0, "/Users/xxxx/canopy/lib/python2.7/site-packages")`, Then try importing a module from that directory. – Ankit Sultana Jul 04 '15 at 21:47
  • 1
    For a more permanent fix, and if previous way worked use [site](https://docs.python.org/2/library/site.html) tl;dr do this in terminal in your case, `echo "/Users/xxx/canopy/lib/python2.7/site-packages" >> /Library/Python/2.7/site-packages/usrlocal.pth`. – Ankit Sultana Jul 04 '15 at 21:57
  • Thank you bk2dcradle! This works. But is it possible to also make my terminal current session (not the python session) import modules from "/Users/xxxx/canopy/lib/python2.7/site-packages"? I'm asking this because normally I use terminal to start "ipython notebook", and I import the modules on the html notebook from the path "/Users/xxxx/canopy/lib/python2.7/site-packages". But now I can't directly command "ipython notebook" in terminal. I still like to keep doing it that way if it is possible. Thanks a lot! – user2855528 Jul 04 '15 at 21:57
  • I just saw this before I type my last question! I think this answers it but I tried and I got this "-bash: /Library/Python/2.7/site-packages/usrlocal.pth: Permission denied". – user2855528 Jul 04 '15 at 22:00
  • This should answer it use `sudo echo "/Users/xxx/canopy/lib/python2.7/site-packages" >> /Library/Python/2.7/site-packages/usrlocal.pth` – Ankit Sultana Jul 04 '15 at 22:10
  • unfortunately, adding "sudo" doesn't work. It still says "/Library/Python/2.7/site-packages/usrlocal.pth: Permission denied". – user2855528 Jul 04 '15 at 22:14
  • 1
    Then do it by first navigating `cd /Library/Python/2.7/site-packages/`, then `sudo vim usrlocal.pth`, enter password, paste `/Users/xxx/canopy/lib/python2.7/site-packages` – Ankit Sultana Jul 04 '15 at 22:18
  • Now my python can import directly from "/Users/xxx/canopy/lib/python2.7/site-packages ". Thanks a lot! However, and I'm sorry about it, I don't think this solved all my issues. I still can't directly launch "ipython notebook" from terminal. I need to directly launch "ipython notebook" because all my previous code are in the notebook format. The "ipython" module exist in " /Users/xxx/canopy/lib/python2.7/site-packages" but not "/Library/Python/2.7/site-packages/". – user2855528 Jul 05 '15 at 01:28
0

I found the solution:

added to the bash_profile this line " export PATH="$HOME/canopy/bin:$PATH" ", and uncomment all other lines in bash_profile.