Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell Homebrew to install inside virtualenv?

Here's my problem. I can't install MatPlotLib both via pip and from source (Matplotlib installation on Mavericks). I tried brew install matplotlib and the installation successfully ended. However, it installed MatPlotLib globally and not inside the currently activated VirtualEnv.

Is it possible to tell brew to install a package inside the current VirtualEnv?

like image 879
se7entyse7en Avatar asked Sep 06 '14 14:09

se7entyse7en


1 Answers

All that a virtual environment does is change what Python interpreter will be invoked by modifying the PATH variable. Homebrew doesn't look at that because it doesn't use Python to install packages (like pip does). By design, as Tim said, Homebrew installs inside its own prefix every time.

One could conceive of a modified Python virtual environment that also installs its own copy of Homebrew, but that would be almost entirely a bad thing.

What you can do, if you want Homebrew packages in a virtual environment, is to enable system site packages in the venv (in Python3, this would be python3 -m venv --system-site-packages ~/path/to/venv). This can be done to update existing virtual environments, as well.

Enabling system site packages allows Python to use globally installed packages, but it will still search inside the venv first, and you can override global packages by installing something with pip. As far as I can tell, this is as close as you'll get to The Right Way in that situation.

like image 160
krs013 Avatar answered Sep 27 '22 19:09

krs013