Working inside a vagrant environment, inside a python virtual environment, when I try to install a python package using
(venv) vagrant@vagrant-ubuntu-trusty
The root problem is that sudo
does not by default inherit the user's environment as it executes the command. This is what you want - trust me on this.
In your case, your pip
is either guided to the venv that it can't write to or - under sudo - to root's environment where you don't want it to be.
The solution you posted is actually valid: If you use sudo, be sure to tell it exactly what to do, how to do it and whom to do it to! All of the aforementioned can be controlled by the user's environment variables so caution is key.
You may also use sudo -E
, which does inherit the calling user's environment and should therefore preserve your venv. Be sure to read sudo
's man-page or do some googling about all the possible trouble you could get in, though.