0

I have been using Mac python for a while, and I decided to teach myself matplotlib, because I want to have the experience with some common modules. I hear from everyone that once you get into non-standard modules, it's best to use python threw homebrew, so you have access to pip and not easy_install. After running: $brew install python --with-brewed-openssl, $brew install python3 --with-brewed-openssl, and $pip install matplotlib, I go to the python shell with $python3. Once there, I run import matplotlib.pyplot as plt, and get the following:

Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 00:54:21) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'matplotlib'
>>>

I have a feeling I'm still using the mac python, and not the brewed python, and I have tried editing the path, but it isn't working, even though I am running $source ~/.bash_profile after every edit. Just in case I am editing the path wrong, I will post the file contents below:

PATH=/usr/local/bin:/usr/local/sbin:/opt/iOSOpenDev/bin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
PATH=/usr/local/opt/ruby193/bin:/usr/local/bin:/usr/local/sbin:/opt/iOSOpenDev/bin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
export MSF_DATABASE_CONFIG=/usr/local/share/metasploit-framework/database.yml

PATH="/Users/ericmarkmartin/.apportable/SDK/bin:$PATH"

PATH="/Users/ericmarkmartin/.apportable/SDK/bin:$PATH"

# Setting PATH for Python 3.4
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
PATH=“/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/bin:${PATH}”
export PATH
PATH=/usr/local/bin:/usr/local/sbin:/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/Users/ericmarkmartin/.apportable/SDK/bin:/Users/ericmarkmartin/.apportable/SDK/bin:/usr/local/opt/ruby193/bin:/usr/local/bin:/usr/local/sbin:/opt/iOSOpenDev/bin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Users/ericmarkmartin/.rvm/bin
PATH=/usr/local/opt/ruby193/bin:/usr/local/bin:/usr/local/sbin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/Users/ericmarkmartin/.apportable/SDK/bin:/Users/ericmarkmartin/.apportable/SDK/bin:/usr/local/opt/ruby193/bin:/usr/local/bin:/usr/local/sbin:/opt/iOSOpenDev/bin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Users/ericmarkmartin/.rvm/bin
PATH=/usr/local/bin:/usr/local/sbin:/usr/local/opt/ruby193/bin:/usr/local/bin:/usr/local/sbin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/Users/ericmarkmartin/.apportable/SDK/bin:/Users/ericmarkmartin/.apportable/SDK/bin:/usr/local/opt/ruby193/bin:/usr/local/bin:/usr/local/sbin:/opt/iOSOpenDev/bin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Users/ericmarkmartin/.rvm/bin
PATH=/usr/local/bin:/usr/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/iOSOpenDev/bin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin:/usr/local/opt/ruby193/bin:/usr/local/bin:/usr/local/sbin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/Users/ericmarkmartin/.apportable/SDK/bin:/Users/ericmarkmartin/.apportable/SDK/bin:/usr/local/opt/ruby193/bin:/usr/local/bin:/usr/local/sbin:/opt/iOSOpenDev/bin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Users/ericmarkmartin/.rvm/bin:/Users/ericmarkmartin/.rvm/bin
PATH=/usr/local/opt/ruby193/bin:/usr/local/bin:/usr/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/iOSOpenDev/bin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin:/usr/local/opt/ruby193/bin:/usr/local/bin:/usr/local/sbin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/Users/ericmarkmartin/.apportable/SDK/bin:/Users/ericmarkmartin/.apportable/SDK/bin:/usr/local/opt/ruby193/bin:/usr/local/bin:/usr/local/sbin:/opt/iOSOpenDev/bin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Users/ericmarkmartin/.rvm/bin:/Users/ericmarkmartin/.rvm/bin

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function

# Setting PATH for MacPython 2.6
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.6/bin:${PATH}"
export PATH
export PATH=/usr/local/bin:/usr/local/sbin:${PATH}

$pip3 install matplotlib returns the following

RuntimeError: Broken toolchain: cannot link a simple C program

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /private/var/folders/sr/j0s763cj06v38c6btg6v7k7r0000gn/T/pip_build_ericmarkmartin/matplotlib
Storing debug log for failure in /Users/ericmarkmartin/.pip/pip.log

If more information is needed, please feel free to ask, and thank you so much in advance for the help!

ericmarkmartin
  • 717
  • 1
  • 8
  • 19
  • Try using a verbose flag `pip --verbose install matplotlib` and see which Python version mentioned. – Beta Decay Aug 22 '14 at 07:21
  • Hopefully [THIS](http://www.tapir.caltech.edu/~dtsang/python.html) will help :) – Tanmaya Meher Aug 22 '14 at 07:34
  • Thanks so much for the answer, I will check it out in the morning and gladly mark this as a solution of it works out. – ericmarkmartin Aug 22 '14 at 07:39
  • I followed [these](http://hackercodex.com/guide/python-development-environment-on-mac-osx/) instructions to get homebrew and python installed on Mavericks, and everything works fine now, including `pip` and `virtualenv`. Hope this can help you out as well. – DocZerø Aug 22 '14 at 13:48
  • 1
    What do `which python3` and `head -1 $(which pip3)` return? – Tim Smith Aug 22 '14 at 16:29
  • @Kristof That's funny actually, I used those instructions too. Thanks for the suggestion though. @TanmayaMeher I thanks for the suggestion, but I already had all of those packages installed in brew, so it didn't fix. @TimSmith `$which python3` returns /usr/local/bin/python3 which is an alias that points to an executable in /Library/Frameworks/Python.framework/Versions/3.4/bin/. `$head -1 $(which pip3)` returns #!/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4. – ericmarkmartin Aug 22 '14 at 18:32

2 Answers2

1

pip usually installs modules for python2 if you have both python versions in your system, so for python3 you will probably need to use pip3.

For reference: https://docs.python.org/3.4/installing/index.html

rayryeng
  • 102,964
  • 22
  • 184
  • 193
  • Thanks for the response! However, I already tested the import on python2, and running pip3 doesn't change anything. – ericmarkmartin Aug 22 '14 at 07:29
  • I think this might help [link]http://stackoverflow.com/questions/22388519/problems-with-pip-install-numpy-runtimeerror-broken-toolchain-cannot-link-a, it seems to be a problem with native extensions on OSX, so you should use ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future $pip3 install --upgrade matplotlib –  Aug 23 '14 at 03:04
  • Thanks for the suggestion. That seemed to work for `pip install --upgrade numpy` and `pip install --upgrade matplotlib` but no success with either `pip3 install --upgrade numpy` or `pip3 install --upgrade matplotlib` in addition, `import matplotlib` still fails in both python and python3. – ericmarkmartin Aug 25 '14 at 17:28
0

You can check where a command is coming from by using which python . In this case you are adding /opt/local/bin/ to your path, but then you are adding /Library/Frameworks/Python.framework/Versions/2.6/bin and /usr/local/bin/ before them (you are prepending in each case). $PATH stops on the first successful match, so you won't pick up the python from /opt/local/bin . Try moving that line to the end of your bashrc or adding another line prepending it to the front of $PATH.

Thomas Nelson
  • 693
  • 5
  • 17
  • is /opt/local/bin where brew keeps it's python's. I thought it kept it in the cellar. Also, /opt/local/bin doesn't exist on my computer – ericmarkmartin Aug 22 '14 at 18:57
  • I was confusing homebrew and macports; macports is the one that uses /opt/local/bin/ . What does `which python3` return for you? – Thomas Nelson Aug 23 '14 at 16:17
  • The result of `which python3` can be found above in one of my comments. Homebrew keeps its stuff in /usr/local/Cellar. – ericmarkmartin Aug 23 '14 at 17:19