问题
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?
回答1:
I help maintain the homebrew-python tap. This is not and will not be supported and there probably isn't an easy way to do it.
This is due to the fact Homebrew installs packages to Homebrew's prefix, which is necessarily global. Homebrew doesn't know about virtualenvs or how to install packages into them. Changing that would violate a core assumption of Homebrew's design, i.e. that packages are always installed to their private Homebrew prefix.
Sorry!
回答2:
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.
来源:https://stackoverflow.com/questions/25701133/how-to-tell-homebrew-to-install-inside-virtualenv