1

I am using Mac OSX 10.10.1. I generally use brew or pip to install everything. I noticed that my virtualenv was always grabbing all of my locally installed Python packages. I fixed this by deleting my $PYTHONPATH variable in my ~/.zshrc configuration file. This fixed the problem of the virtualenv grabbing all of my Python packages, but then IPython could not find things located in /usr/local/lib/python2.7/site-packages. I eventually found a way to fix the IPython problem by changing the hashbang line in /usr/local/bin/ipython to #!/usr/local/bin/ipython, as recommended in this SO post. As far as I can tell, everything is working fine now.

My question(s):

  1. Is it best to install everything into /Library/Python/2.7/site-packages? Or is it better to have half of your stuff in /usr/local/lib/python2.7/site-packages? It seems schizophrenic to have one's packages split up that way.

  2. Did I do the right thing by a) deleting my personally defined $PYTHONPATH variable, and b) changing the hashbang from #!/usr/bin/ipython to #!/usr/local/bin/ipython in the /usr/local/bin/ipython file? My $PYTHONPATH variable to been set to export PYTHONPATH="/usr/local/lib/python2.7/site-packages/":${PATH} in the ~/.zshrc config file.

Community
  • 1
  • 1
cjohnson318
  • 3,154
  • 30
  • 33

1 Answers1

1
  1. It's best to install packages within a virtualenv as much as possible (for applications or projects that you're working on). This keeps the dependencies separate and as such you should only install things globally when that's appropriate (but often it's not because a dependency is specific to a project).

    But to answer your question: it's indeed possible that some dependencies are systemwide and others are in the virtualenv. It's a bit weird to have systemwide Python, user Python and virtualenv Python working together but it can be done. Try to avoid spreading out your dependencies everywhere because that's hard to maintain. Combining brew / pip is also a recipe for disaster as they're not always aware of each other and they interfere indeed. I use MacPorts (or Homebrew) for non-Python dependencies and Python interpreter installation and pip for all Python packages.

  2. It doesn't sound right: you should not have to edit the hashbang of a file (unless, of course, as a workaround for a package that was released with a bug). Updating a PYTHONPATH variable is normal as many have such modifications in their shell profile. Your edit to the file is not sustainable as upgrades or other changes may break things again. Provided you're using a correctly packaged release you shouldn't have to point to another Python interpreter.

Community
  • 1
  • 1
Simeon Visser
  • 118,920
  • 18
  • 185
  • 180
  • I second that brew, pip, and virtualenv interact painfully. – pcurry Dec 17 '14 at 23:52
  • Should I move all of my Python packages to `/Library/Python/2.7/site-packages`? That seems a bit hacky too because `setuptools` and pip seem to install everything in `/usr/local/lib/python2.7/site-packages`. – cjohnson318 Dec 17 '14 at 23:57
  • Run `which python` and `which pip` and use that location for installating Python packages that don't belong to a virtualenv. For everything else, use virtualenv and install packages inside the virtualenv. So, short answer, most of your packages should be inside a virtualenv and only a few outside. – Simeon Visser Dec 18 '14 at 00:11
  • Are you sure? Python and pip are both located in `/usr/local/bin/` and pip, by default, installs things elsewhere. Putting everything in `/usr/local/bin` seems counterintuitive. – cjohnson318 Dec 18 '14 at 00:56
  • Those are the Python versions I use: the Python/pip outside the virtualenv and those inside. I think that's the aim: for Python/IPython to have the same deps outside the venv, so they'd share what pip installs – Simeon Visser Dec 18 '14 at 08:47