How to make sure you call pip only in virtualenv?

前端 未结 2 956
萌比男神i
萌比男神i 2021-01-02 10:18

How to prevent accidentally calling pip when I am not in a virtualenv?

I wrote the following script called pipand added it to my ~/bin (whi

相关标签:
2条回答
  • 2021-01-02 10:42
    export PIP_REQUIRE_VIRTUALENV=true
    
    0 讨论(0)
  • 2021-01-02 10:43

    I'd recommend putting this in your ~/.bashrc file:

    export PIP_REQUIRE_VIRTUALENV=true
    

    and you can also add the following function to your ~/.bashrc that allows you to explicitly call pip outside of a virtual environment if you so choose:

    gpip() {
       PIP_REQUIRE_VIRTUALENV="" pip "$@"
    }
    

    Now you can still use your global pip version for doing things like upgrading virtualenv:

    gpip install --upgrade pip virtualenv
    
    0 讨论(0)
提交回复
热议问题