In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how to use pipenv to manage python virtual environment, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Pipenv is the work of the great god Kenneth Reitz, which can effectively manage multiple environments and packages of Python. In the past, we generally used virtualenv to build a virtual environment to manage python versions, but the use of cross-platforms is not consistent, and sometimes there are always problems in dealing with the dependencies between packages; in the past, we often use pip to manage packages. Pip is good enough, but we still recommend pipenv, which is equivalent to the combination of virtualenv and pip, and is more powerful. After pipenv is open source, it is very popular on GitHub (as of now there are more than 9600 stars).
Pipenv has the following main features:
The main results are as follows: (1) pipenv integrates the functions of pip,virtualenv and improves some of their defects.
(2) in the past, it may be a problem to use virtualenv to manage requirements.txt files. Pipenv uses Pipfile and Pipfile.lock, the latter stores the dependencies of the package, and it is very convenient to view the dependencies.
(3) Hash check is used everywhere, which is very safe to install or uninstall packages, and security vulnerabilities are automatically exposed.
(4) simplify the development workflow by loading .env files.
(5) Python2 and Python3 are supported, and the commands are the same on all platforms.
The following describes the whole process of using pipenv to manage python virtual environment, let's take a look!
Python's virtual environment can create a separate environment for the project, which can solve the problem of conflicts caused by using different versions of dependencies. There are many ways to create a virtual environment. Pipenv automatically manages virtual environments and dependent files for you, and provides a series of commands and options to help you implement various dependency and environment management-related operations.
1. Install pipenv
Pip install pipenv
2.Pipfile files and Pipfile.lock files
The Pipfile file and Pipfile.lock are generated when creating a virtual environment to record installation dependencies, and Pipfile is used to replace pip's requirements.txt.
Pipfile.lock contains your system information, all installed package dependencies and their versions, and hash check information for all installed packages and their dependent packages.
3. Create a virtual environment
$cd myproject
/ / create a virtual environment for python3.7
$pipenv-python 3.7
Creating a virtual environment will find out if there is a .venv directory in the current directory by default, and if not, create a virtual environment directory in / Users/xxxx/.local/share/virtualenvs under the home directory user by default. It is recommended that you create a .venv folder under the project before creating a virtual environment.
If pipfile does not exist, a piffle is generated, and the file is automatically edited if any libraries are added.
4. Activate / enter pipenv shell
$pipenv shell
$python-version
/ / install dependencies according to Pipfile, ignoring Pipfile.lock
$pipenv install-skip-lock
/ / install the specified version of the module
$pip install pymongo==xxx
Install dependency packages according to Pipfile.
5. Exit the virtual environment
$exit or ctrl+d
6. View installed dependencies
$pipenv graph
7. Update upgrade package
$pipenv update requests
8. Install a virtual environment through requirements.txt
Pipenv install-r requirements.txt
9. Generate requirements.txt file
Pipenv lock-r [--dev] > requirements.txt
10. Delete virtual environment
Pipevn-rm
The above is all the contents of the article "how to use pipenv to manage python Virtual Environment". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.