Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Pipenv

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to use Pipenv". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

What is Pipenv?

Pipenv is Python packaging tool, an upgrade to use Pip, Venv, and requirements.txt. Pipenv is a great way to combine package management with virtual environments.

Why do we need package management and virtual environments?

According to Wikipedia,

A package manager or package management system is a set of software tools that automate the process of installing, upgrading, configuring, and removing computer programs for a computer operating system in a consistent manner.

Package Manager automates the process of installing, uninstalling, and maintaining packages. This helps developers manage project dependencies easily.

You can read more about the package manager here.

Now let's talk about virtual environments,

A virtual environment is a self-contained directory tree that contains Python installations for a particular Python version, as well as many other packages.

Virtual environments enable us to have a specific unique python installation for each project. This prevents us from overloading the global python installation and enables us to use different versions of python for each project.

Python virtual environments also help isolate the individual dependencies of each project and prevent code breaks in the case of any project specifically configured for Python versions.

You can learn more about virtual environments here.

Now that we understand what package managers are and why we need them, let's start installing Pipenv.

How to install Pipenv?

To install pipenv, open a terminal window and run the following command:

$ pip install pipenv How do I create a virtual environment using Pipenv?

Navigate to the directory where you want to create the virtual environment and open a terminal window and type the following command.

$ mkdir my_project$ cd my_project/$ pipenv install How do I start a virtual environment using Pipenv?

To start the virtual environment, type the following command in the directory.

$ pipenv shell

You will see a project name in parentheses indicating that we have successfully entered the required Python virtual environment.

To exit the virtual environment, we can type,

$ exit How do I check which Python installation is being used?

To check the Python installation in use, we can use the following 3 methods,

Method 1:

With the python shell active, type the following command,

$ which python

This will return the path to the python environment currently in use.

Method 2:

Enter this in the active python shell,

$ import sys$ sys.executable

This will return the Python installation path in use.

Method 3:

To find the path to the executable file without activating the shell, we can use the following command:

$ pipenv --venv How do I install packages using Pipenv?

Type the following code to install a package using Pipenv.

$ pipenv install How do I run Python commands without activating a virtual environment in my current environment?$ pipenv run python

To run the file, use the following command:

$ pipenv run python How to use the requirements.txt file in Pipenv?

To install dependencies and packages using pip's requirements.txt, use the following command:

$ pipenv install -r How do I create a requirements.txt using Pipenv?

The following commands can be used to generate the content of requirements. txt:

$ pipenv lock -r

To create a requirements.txt, we can redirect this output to our requirements. txt:

$ pipenv lock -r > requirements.txt How do I uninstall packages using Pipenv?

The following commands can be used to uninstall packages using pipenv:

$ pipenv uninstall

To uninstall all packages, use the-all flag.

How do I delete a virtual environment using Pipenv?

The following commands can be used to safely delete packages using pipenv:

$ pipenv -rm Other things to know about Pipenv:

By default, pipenv is ~/.local/share/virtualenvs/.

To install packages that should not be included in production releases, we can use the--dev flag at the end of the install command.

To check for security vulnerabilities in a virtual environment, we can use the following command:

$ pipenv check。

You can trace all dependencies of a project using the following command:

$ pipenv graph.

"How to use Pipenv" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report