0

I currently have Python2.7, and Python3.3 installed on a Mac. I am trying to install matplotlib so that I can create candlestick, and line graphs. I have tried multiple methods of installing matplotlib, but they are all failing. For example:

port install py27-matplotlib
No broken files found.
MacBook$ python2.7
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53) 
>>> import matplotlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named matplotlib

attempts at source builds off matplotlib-1.1.1 lead to C header errors.

The parent problem that I am trying to solve is to create candlestick, and line plots. Is there another library better suited to this maybe?

tacaswell
  • 84,579
  • 22
  • 210
  • 199
stubble jumper
  • 275
  • 1
  • 4
  • 10
  • It is very simple to do with R. You can interface R from Python with Rpy: http://rpy.sourceforge.net/ – The Unfun Cat Nov 07 '12 at 21:07
  • 2
    Does `which python` give you the Python installed through MacPorts? – Fred Foo Nov 07 '12 at 21:09
  • 1
    This isn't a problem with the library's capabilities, but rather of your installation of it (it wont even import!)... you should explain how you have attempted to install it. – Andy Hayden Nov 07 '12 at 21:11
  • 2
    "Use R" isn't really a useful answer. He's asking how to do plotting in Python. – Iguananaut Nov 07 '12 at 21:36
  • Remove all traces of macports from your system and install [Python from Homebrew](https://github.com/mxcl/homebrew/wiki/Homebrew-and-Python) – jterrace Nov 07 '12 at 21:50
  • jterrace, That's not a very useful suggestion. There's nothing inherently better about using Homebrew over MacPorts. They both have their strengths and weaknesses. The problem here is a simple one-time PATH problem. – Ned Deily Nov 07 '12 at 22:18

2 Answers2

0

seems like you have a python's path issue and maybe this post will be helpful.

update: i reemphasized my hint at the path issue because of a comment...

Community
  • 1
  • 1
Don Question
  • 11,227
  • 5
  • 36
  • 54
  • When you install third-party Python packages, like matplotlib, with MacPorts via a pynn-x port, they are installed into a MacPorts Python instance. You need to use that Python; if you do, there is no need to set `PYTHONPATH`. And there may be difficulties trying to force running of those installed packages with another Python (like an Apple-supplied system Python) as the build configuration of the two Pythons may be incompatible (architectures, deployment target, etc). – Ned Deily Nov 07 '12 at 22:24
  • that may be valid objections, but i don't see how that warrants a downvote to a 1st most likely cause of his problem with 2nd link to an ACCEPTED answer and 3rd i DIDN'T propose a change to his PYTHONPATH - enviroment variable, but merely hinted the cause! btw. the linked answer does stress the point with the port supplied python version... – Don Question Nov 07 '12 at 22:29
  • The `PYTHONPATH` environment variable (as in the original answer) is totally different from the `PATH` environment variable. So, yes, your edited answer is better. – Ned Deily Nov 07 '12 at 22:36
  • Def pointed me towards the solution. Thanks. The Unfun Cat, I had tried Rpy, and Rpy2, but found the number of graphing examples of the interface into R a little low. Are there some somewhere? – stubble jumper Nov 07 '12 at 22:48
0

You need to use the MacPorts-supplied Python 2.7, not the Apple-supplied system Python 2.7. Try:

/opt/local/bin/python2.7

To avoid having to use absolute paths, make sure that the recommended MacPorts bin directories are on your shell PATH and run sudo port select python python27 to select the MacPorts Python 2.7 as the default for /opt/local/bin/python.

Ned Deily
  • 83,389
  • 16
  • 128
  • 151