This is the 28th day of my participation in the First Challenge 2022

Pipenv

The main purpose of Pipenv is to provide an easy way for users and developers of applications to set up their working environment.

The installation

Very simple, direct PIP installation can be very convenient.

pip3 install pipenv
Copy the code

You are advised to install an image source, which is fast and difficult to fail. Note in advance: if the big guy does not like, do not spray, welcome comments and suggestions.

pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple pipenv
Copy the code

Here are some common mirror sources:

Ali cloud http://mirrors.aliyun.com/pypi/simple/ https://pypi.mirrors.ustc.edu.cn/simple/ douban China university of science and technology http://pypi.douban.com/simple/ https://pypi.tuna.tsinghua.edu.cn/simple/ university of science and technology of China, tsinghua university http://pypi.mirrors.ustc.edu.cn/simple/Copy the code

Creating a Virtual Environment

1. Create a directory

Open terminal /CMD, enter the following command, for example, I myself first go to my project directory /Users/ XKS /Envs, then create a new project folder sklearn_env, in the project folder to create a.venv folder, for the virtual environment.

cd /Users/xks/Envs && mkdir sklearn_env
cd sklearn_env && mkdir .venv
Copy the code

2. Create a virtual environment

Enter the following command to create the virtual environment in the project folder. If we create a. Venv folder, the virtual environment files will be automatically stored in that folder.

pipenv install
Copy the code

At the end of the run, sklearn_env will generate two files (in the screenshot below, I did not create a.venv folder, so the virtual environment files will be generated and stored in the default path).

  • Pipfile Records the list of dependent packages for the project. Replace with tsinghua University image source installation, the late installation package is fast.

  • Pipfile.lock records a detailed list of dependencies for fixed versions.

3. Enter the virtual environment

In the project folder where you created the virtual environment, enter the following command to enter the virtual environment.

pipenv shell
Copy the code

4. Install the module in the virtual environment

Pipenv install (which writes the installed modules and dependencies to the pipfile.lock file) and PIP install (which installs the modules directly into the virtual environment, but does not record them) can be used by third parties.

pipenv install scikit-learn
Copy the code

As you can see from the image above, there is a sign in front of the virtual environment, which is the name of the virtual environment. By default, the virtual environment name is the project directory.

5. Check the modules installed in the virtual environment

The pipenv Graph can be used to view installed packages, and associated dependent environment packages, or directly through the PIP List.

Pipenv graph or PIP ListCopy the code

6. Reference pipenv virtual environment in Pycharm

First we check the location of the virtual environment with the pipenv –venv command.

Pipenv - venv run results: / Users/XKS/local/share/virtualenvs/sklearn_env - nfwWy6XnCopy the code

Then copy the directory above and use Pycharm to create a new project, specifying the project environment.

7. Delete the virtual environment

Sometimes our project is not needed, and we want to delete the corresponding virtual environment, how to do?

Directly in the project directory open terminal/CMD, enter the following command to delete the virtual environment files, in addition, we also need to delete the project folder pipfile and pipfile.lock files.

pipenv --rm                 
Copy the code

8. Common commands

Here are some common pipenv instructions.

Pipenv --venv pipenv --py Pipenv --py Pipenv pipenv --where pipenv --where pipenv --where pipenv --where Generate Pipfile and pipfile. lock pipenv isntall [Moduel] installation packages/modules in the directory, Pipenv install[Moduel] --dev uninstall packages to the development environment pipenv uninstall[module] --all Uninstall all packages/modules pipenv Pipenv run python [pyfile] Run python file pipenv --rm delete the virtual environmentCopy the code

Why do you recommend Pipenv

The python library is used for data analysis. The python library is used for data analysis. The Python library is used for data analysis. Now want to do some things to yourself and in your free time web, crawler, machine learning, etc., all want to try, so before you begin, reasonable planning and management is necessary to the local environment, I chose Pipenv, really comfortable to use, don’t need a lot of reason, what a great god work, much better than what what, the most convenient and quick, As you can tell from the article, it’s simple and comfortable.

So, if you think it is appropriate, then use it, if you don’t catch a cold, just ignore it, of course, welcome to share their better methods, learn together, and make progress together.

The resources

[1]Pipenv: Python Dev Workflow for Humans: pipenv.pypa.io/en/latest/

[2] Pipenv, had better use the python virtual environment and package management tool: www.cnblogs.com/zingp/p/852…

Persistence and hard work: results.

Like to see the message forwarding, four support, the original is not easy. Ok, see you next time, I love the cat love technology, more love si si’s old cousin Da Mian ଘ(˙꒳˙)ଓ Di Di