[PYTHON] Introduction of pipenv (also create requirements.txt)

Introduction

Since we introduced pipenv, we will summarize the environment construction method.

I want to create requirements.txt without extra packages, so use the dev option to separate the packages to be imported in the code from the packages installed to build the environment.

It would be very helpful if you could point out any mistakes.

environment

Installation of pipenv

pip install pipenv

Install pipenv in your local environment.

Creating a virtual environment

Enter the directory where you want to use the virtual environment

pipenv install --python=3.7.6

Create a virtual environment with. Specify the version you want to use as appropriate.

At the same time, ** Pipfile ** and ** Pipfile.lock ** are created in the current directory.

ls

You can see that the file has been created in.

Installation of required libraries

pipenv install [package]

You can install the package in the virtual environment without entering the virtual environment with. For example

pipenv install numpy

Then you can install numpy.

--dev option

pipenv install --dev [package]

You can install it as a development package using the --dev option.

Install the package used to build the environment using the dev option, and install it. Packages that are imported in the code will be installed without this option.

Checking packages in a virtual environment

pipenv lock -r

A list of packages in the virtual environment (other than those entered with --dev) is displayed with.

pipenv lock -r -d

You can check the package of the development environment with.

pipenv run pip freeze

You can check all the packages included in it.

Creating requirements.txt

pipenv lock -r > requirements.txt

You can create requirements.txt in the current directory with

Delete and clean Pipfile

pipenv uninstall [package]

Uninstall the package

pipenv clean

Delete the dependent packages that remain even after uninstalling the package.

[Reference] https://qiita.com/eduidl/items/c0e8256bb3a5a735d19c

pipenv --rm

Delete the virtual environment.

Other commands

pipenv --venv

Get the path of the virtual environment. It can be used to check if there is a virtual environment.

pipenv shell

Enter the virtual environment.

exit
Get out of the virtual environment

Postscript

Since jupyter lab and VScode have a mechanism that allows you to select a virtual environment, switch kernel
You can change the virtual environment by clicking.

Recommended Posts

Introduction of pipenv (also create requirements.txt)
Introduction of Python
Introduction of scikit-optimize
Introduction of PyGMT
Introduction of cymel
Introduction of Python
Introduction of trac (Windows + trac 1.0.10)
Introduction of ferenOS 1 (installation)
Introduction of Virtualenv wrapper
[Introduction to cx_Oracle] Overview of cx_Oracle
Introduction of activities applying Python
Migrate from requirements.txt to pipenv
Introduction of caffe using pyenv
Introduction and tips of mlflow.Tracking