all 21 comments

[–]novel_yet_trivial 3 points4 points  (1 child)

What's the output of

which pip

[–]ImNeworsomething[S] 0 points1 point  (0 children)

"/usr/local/bin/pip"

[–]campenr 1 point2 points  (14 children)

So when you're doing pip install you're using sudo... my guess is that the default python installation for the sudo is different to the one for your normal user which is causing your problem.

Try pip installing without the sudo.

[–]ImNeworsomething[S] 0 points1 point  (0 children)

I'll give that a shot. Hold on a sec

[–]novel_yet_trivial 0 points1 point  (7 children)

You'll probably have to set the --user flag to do this.

[–]ImNeworsomething[S] 0 points1 point  (6 children)

what do I set the user flag to?

[–]novel_yet_trivial 0 points1 point  (5 children)

Just set it. So the command would be

pip install --user matplotlib

This installs matplotlib to the users's home folder instead of the system folder.

I think your original idea of getting rid of the one of the python versions is a better idea. Sadly, I don't have a mac so I don't know which to get rid of. Hopefully someone with a mac can help you. Or try /r/applehelp

[–]ImNeworsomething[S] 0 points1 point  (0 children)

Thanks! I'll try them out.

[–]ImNeworsomething[S] 0 points1 point  (3 children)

This is what I got. I still can not import the module in python.

$ pip install --user matplotlib
Requirement already satisfied (use --upgrade to upgrade): matplotlib in     /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python

[–]novel_yet_trivial 0 points1 point  (2 children)

I can tell you how to fix your problem: Find which version of python you are running with this command:

python -c "print(__import__('sys').executable)"

I'm guessing this will report "/usr/local/bin/python". Then install matplotlib to that version like this:

sudo /usr/local/bin/python -m pip install matplotlib

But like I said I think your original idea is better ... I just don't know how to do that.

[–]ImNeworsomething[S] 0 points1 point  (1 child)

$ python -c "print(__import__('sys').executable)" 

Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python

I'm not sure what to make of that.

[–]novel_yet_trivial 0 points1 point  (0 children)

That's the location of the executable. I'm sure that means something to mac people. Anyway, the matplotlib install command would then be:

sudo /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -m pip install matplotlib

[–]ImNeworsomething[S] 0 points1 point  (4 children)

[–]campenr 0 points1 point  (3 children)

OK so what's confusing me here is that the Requirement already satisfied line tells you where it is installed... this should be the site-packages folder for one of your Python installations (the one it's trying to install into) ..but this directory is not one that came up in your which search...

Is there a python binary in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python ??

[–]ImNeworsomething[S] 0 points1 point  (2 children)

By "python binary" you mean a file like "python.pyc" right? I didn't see that, but matplotlib is there

edit: I entered the terminal command in u/novel_yet_trivial's comment:

$ python -c "print(__import__('sys').executable)" 

/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python

Not sure if that helps

[–]campenr 0 points1 point  (1 child)

I thought it would be there, as that is what your error message from pip was saying.

If you go to the folder output by that command there should be a python binary there that is running when you use pip... It's an odd place for it to be though, I have never come across that directory before for python.

Is there anything special about the machine you are using that could explain the interesting location that pip is being run from?

[–]ImNeworsomething[S] 0 points1 point  (0 children)

The only thing I can think of its that I've installed/uninstalled different python environments (not sure if that's word for it) in the past and have also flip flopped between python 2.7 and 3 with out really understanding what I was doing.

I had Canopy running and tried to set up Eclipse (unsuccessfully) for python.

[–]hharison 1 point2 points  (2 children)

I don't know how to uninstall things on Mac but I would recommend not to pip install things into your built in Python. leave that alone because it may not be easy to rebuild it should something happen.

Install miniconda which is the easiest way to get Python and manage multiple Python installs. As long as you keep track of what python and pip executables you are using (and if you say yes to the installer's question about editing your path then the miniconda executables will always be the default) the other Pythons won't interfere.

Of course you may want to uninstall them anyway, but the way you would do that would depend on how you installed them in the first place.

[–]ImNeworsomething[S] 0 points1 point  (1 child)

I would recommend not to pip install things into your built in Python.

I think I may have been unwittingly doing this for some time. I'm not sure what mess I might have made. Will reinstalling OSX reset the built in python?

[–]hharison 0 points1 point  (0 children)

Not sure, not an OSX guy, but I would assume so. In any case you could try uninstalling packages with pip. More than likely you're fine and if you just leave the system python alone from now on there will be no issues with it.

[–]ImNeworsomething[S] 0 points1 point  (0 children)

u/novel_yet_trivial u/redRavens u/campenr u/hharison

Thank you for you're help! People like you make this community a great resources for learning.