Inside virtual env, “sudo pip” links to the global python pip

前端 未结 3 1263
不知归路
不知归路 2021-01-17 17:06

Working inside a vagrant environment, inside a python virtual environment, when I try to install a python package using

(venv) vagrant@vagrant-ubuntu-trusty         


        
3条回答
  •  旧巷少年郎
    2021-01-17 17:42

    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.

提交回复
热议问题