简体   繁体   中英

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?

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, ie that packages are always installed to their private Homebrew prefix.

Sorry!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM