Package management: PIP/conda

Virtual environment: VirtualEnv


Disable global installation

Today y I accidentally put the packaging to be installed in the virtual environment into the global, but also with the batch installation list, press enter found that forget to switch the environment heart is cool. Fortunately, a closer look found that most of them are prompted to have been installed, but there are still two leakage fish QAQ

To prevent this from happening again, the global PIP is disabled.

Add the following command to ~/.bashrc (written with ZSH to ~/.zshrc) :

export PIP_REQUIRE_VIRTUALENV=true # Forbid pip install in global environment
gpip() { # global pip

As you can see, a function has also been added incidentally so that GPIP can be used instead of global PIP when it is really needed.

At this point, all PIP commands must be run in the virtual environment, and even simple query functions such as PIP List must be called through GPIP. Feel at ease.



Creating a virtual environment
$ virtualenv testenv

A folder named testenv will appear in the current directory

Enter the virtual environment
$ source testenv/bin/activate

Command-line prompts will be prefixed with (testenv)

Exit the virtual environment
$ deactive

The prefix will disappear and return to the global environment

Delete the virtual environment

Delete the entire folder after exiting the virtual environment