When creating Python projects, we usually create a virtual environment, which has the advantage of separating the project environment from the operating system environment and avoiding cluttering the operating system environment.

$graph TD
Start --> Stop$

Another pain point is that after the development environment is finished, we need to copy the code to the production environment and go online. At this time, I don’t want to re-install all the packages of the development environment in PIP Install. What should I do?

classDiagram
Animal <|-- Duck
Animal <|-- Fish
Animal <|-- Zebra
Animal : +int age
Animal : +String gender
Animal: +isMammal()
Animal: +mate()
class Duck{
+String beakColor
+swim()
+quack()
}
class Fish{
-int sizeInFeet
-canEat()
}
class Zebra{
+bool is_wild
+run()
}

So PipenV was born. By definition, PIP V is a combination of PIP and Virtualenv.

Install piP3. — — — — — — — —

Creating a Virtual Environment

Pipfile and pipfile. lock will be automatically generated in your project directory after installation. They are mainly used to manage packages. Let’s try it out by installing the Requests library with Pipenv.Let’s look at the contents of Pipfile and pipfile.lock. The Pipfile lists the requests library information and Python version information. If you’re careful, you may notice that the Pipfile also contains dev-packages information, which will be recorded under dev-packages if the -dev parameter is specified during installation. Pipfile.lock, on the other hand, holds the library’s hash value, which is key to ensuring the consistency of library information in production and development environments.

When you copy your project from the development environment to production, you just need to execute Pipenv install instead of reinstalling the package that was installed in the development environment.

Other commands to enter the virtual environment:

Exit the virtual environment: ————————————————Install the library:Delete library:Upgrade library:View library details:Obtain the local project path:Obtain the path of the virtual environment:Checking library dependencies is very useful.Check the security of the library:Delete a virtual environment:

conclusion

Today we introduce the Python virtual environment pipenv. A good tool can get twice the result with half the effort.

graph TD
Start --> Stop