1

In attempting to get started learning and developing python, I've tried to follow the Python Guide to installing python on OS X, but haven't found it particularly "noob friendly." I have a new MacBook (Mtn. Lion - OS X 10.8.3) wich comes with Python 2.7.2 built in. But the guide advises installing a "framework-style build" via homebrew. So:

  1. I installed homebrew via ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"

  2. Then it tells you to add homebrew to the top of your PATH by adding it to your ~/.bashrc file. ls -a showed that I did not have a ~/.bashrc file in my home directory. After searching Stack Overflow on how to do that, I ran nano ~/.bashrc, and inserted the line export PATH=/usr/local/bin:$PATH to the file and saved the file.

  3. I then ran brew install python --framework and the install completed.

  4. Then, the guide says to "add the new Python scripts directory to your PATH" so, I'm assuming that means I need to add the line it provides to my ~/.bashrc file also. So, I added export PATH=/usr/local/share/python:$PATH to my ~/.bashrc file above my previous entry.

  5. Finally, this is where I run into trouble, it says to easy_install pip. However, when I do that I get an error 13.

So, here are the things I need some help with.

  1. Was I correct in my assumptions about how to add homebrew and python scripts to my PATH?

  2. Did I do something wrong or do I just need to use sudo to install pip? (I'm really sorry if the answer is already on this page but even those answers don't make total sense to me and I want to be careful and not screw something up)

  3. After installing the framework-style build of python (which I believe was the current 2.7.3), how come running python in my terminal still shows v2.7.2?

Thanks! I appreciate any help.

Community
  • 1
  • 1
saclark
  • 415
  • 1
  • 4
  • 11

2 Answers2

3

I've tried to follow the Python Guide to installing python on OS X, but haven't found it particularly "noob friendly.

Yes, I think it is misleading/outdated.

Then it tells you to add homebrew to the top of your PATH by adding it to your ~/.bashrc file. ls -a showed that I did not have a ~/.bashrc file in my home directory. After searching Stack Overflow on how to do that, I ran nano ~/.bashrc, and inserted the line export PATH=/usr/local/bin:$PATH to the file and saved the file.

On the Mac, just use ~/.profile

I then ran brew install python --framework and the install completed.

I think you don't need the --framework option unless you want to replace your Mac OS default installation and need an Mac OS Framework-style directory layout. There is no need to replace it though, the homebrew installation will take precedence anyway.

Then, the guide says to "add the new Python scripts directory to your PATH" so, I'm assuming that means I need to add the line it provides to my ~/.bashrc file also. So, I added export PATH=/usr/local/share/python:$PATH to my ~/.bashrc file above my previous entry.

Again, do it in ~/.profile. And don't forget to do a

source ~/.profile

otherwise the changes will only become active in any new terminal window, not the one you are currently using.

Finally, this is where I run into trouble, it says to easy_install pip. However, when I do that I get an error 13.

The error shows that you try to install it your Mac OS system's default Python library (rather than in /usr/local, homebrew style), which would require root privileges. Just don't. Also, with homebrew python, pip is already installed.

Check your path:

$ which pip
/usr/local/bin/pip
$ ls -l /usr/local/bin/pip
[..] /usr/local/bin/pip -> ../Cellar/python/2.7.3/bin/pip

Added bonus: Then do

pip install virtualenv

and use that.

And to your questions:

Was I correct in my assumptions about how to add homebrew and python scripts to my PATH?

Yes, but use .profile and do a source .profile afterwards.

Did I do something wrong or do I just need to use sudo to install pip? (I'm really sorry if the answer is already on this page but even those answers don't make total sense to me and I want to be careful and not screw something up)

You don't need sudo with homebrew, and pip is installed automatically with homebrew python.

After installing the framework-style build of python (which I believe was the current 2.7.3), how come running python in my terminal still shows v2.7.2?

Probably PATH not correct, do echo $PATH and check that it is correct. That is unrelated to being "framework-style" or not, though.

lutzh
  • 4,917
  • 1
  • 18
  • 21
  • thanks! I ran `python` again and it came up with version 2.7.3 after all. Perhaps I just had to restart terminal? I've done what you've suggested and it looks like I'm good to go. – saclark Mar 20 '13 at 01:10
  • However, now it appears I have another issue :(. I've made it a separate question if you care to take a look: http://stackoverflow.com/questions/15513840/distributionnotfound-error-after-upgrading-pip – saclark Mar 20 '13 at 01:50
  • error 13 is because the easy_install from OS X needs sudo. But don't do it because it will install into /Library/Python/2.7 and then conflict with the brewed python because all pythons are configured to look into /Library/Python/x.y/site-packages for modules. Homebrew installs pip and distribute, so you don't need them. The python guide has to be updated. – Samuel John Mar 22 '13 at 09:08
0

If you installed python with homebrew, you should already have pip installed. Try running

pip --version

to see whether and where pip is installed. Hopefully it's in a /usr/local/... path where your other homebrew things live.

Also before you install too much more with homebrew be sure to run these commands:

brew update
brew doctor

Good luck!

askewchan
  • 45,161
  • 17
  • 118
  • 134