Search code examples
pythonmacportspiphomebreweasy-install

How do Homebrew, PIP, easy_install etc. work so that I can clean up


I have a problem that comes from me following tutorials without really understanding what I'm doing. The root of the problem I think is the fact that I don't understand how the OS X filesystem works.

The problem is bigger than Python but it was when I started learning about Python that I realized how little I really understand. So in the beginning I started following tutorials which led me to use the easy_install command a lot and when a lot of tutorials recommended PIP I never got it running. So I have run a lot of commands and installed a lot of different packages.

As I have understood Lion comes with a python install. I have been using this a lot and from this I have installed various packages with easy_install. Is there any way to go back to default installation and begin from the very beginning? Is this something I want to do? If so why?

Is there any advantage of using a Python version I have installed with Homebrew? How can I see from where Python is run when I run the Python command?

When I do install something with either easy_install, homebrew, macports etc where do things actually end up?


Solution

  • Homebrew installs its software inside the /usr/local subdirectory on your Mac. OS X doesn't install anything there on its own; in fact, /usr/local is reserved for user-installed stuff. Since Homebrew never installs files outside /usr/local (and doesn't even have the ability to, unless you run brew using sudo - which is not recommended_) and OS X never installs files inside there, never the two shall mix.

    easy_install and pip install files into system directories by default. That's why you have to run those commands with sudo to install packages with them.

    I can't recommend virtualenv enough, regardless of which OS you're using. It installs a copy of Python, along with any packages or modules you want, inside a directory of your choosing. For example:

    $ cd /tmp
    $ virtualenv foo         
    New python executable in foo/bin/python
    Installing setuptools............done.
    Installing pip...............done.
    $ cd foo
    $ bin/pip install sqlalchemy
    Downloading/unpacking sqlalchemy
      Downloading SQLAlchemy-0.7.7.tar.gz (2.6Mb): 2.6Mb downloaded
      Running setup.py egg_info for package sqlalchemy
    [...]    
    Successfully installed sqlalchemy
    Cleaning up...
    
    [work, work, work]
    [decide this was a bad idea]
    $ cd /tmp; rm -rf foo
    

    ...and all traces of the project are now completely gone.

    Use easy_install to install virtualenv into OS X itself - like you've done for those other packages - but then do all new development inside isolated directories that you can wipe clean at a moment's notice. This is pretty much the standard way of developing and deploying Python applications these days.