Python virtual environment in 2021 ~ There is no reason not to use venv now ~

What are you doing with the Python virtual environment?

One of the attractions of Python is that there are various libraries, so considering library compatibility and stability, I would like to combine a library set and Python version according to the development purpose and switch as needed. Thing. The Python virtual environment makes this possible.

There are many options for Python virtual environments, but if you don't have a lot of Kodawari, ** venv is highly recommended **. I tried to summarize the reasons into three.

For a comparative introduction of virtual environments, "pyenv, pyenv-virtualenv, venv, Anaconda, Pipenv. I use Pipenv." is very well organized. However, venv is categorized as not being able to switch between Python interpreter versions, which is incorrect. As written, venv is almost equivalent to virtualenv. Therefore, the position of ○ should be the same as virtualenv, and the Python interpreter version can be switched. Although different versions can be used for each virtual environment, the same virtual environment version cannot be switched later, which is the same as virtualenv (upgrade is possible).

Reason 1. It's a Python virtual environment, but it's official

Obviously, venv is the recommended virtual environment that comes with the official Python version of Python 3.5 and above.

Support for Python 3.4, which does not support venv, was completed in April 2019, support for Python 2 series ended on January 1, 2020, and the actual final release was April 2020. Until now, there was a reason to use another Python virtual environment because it was said that "venv is official, but it does not correspond to the Python version you want to use", but in 2021 there is no negative reason. It was. ** There is no reason not to use venv now **.

Reason 2. Because the official ecosystem is substantial

In the "official" Python ecosystem, such as qualification exams, educational courses, and corporate dissemination, the prerequisite virtual environment is becoming venv.

Unlike a few years ago, the official ecosystem has grown and ** now there is no reason not to use venv **.

It should be noted that other Python virtual environments such as pyenv dominate in "unofficial" content such as Qiita and other user-participatory content. This kind of user-participation-type content has the characteristic that the previously popular method does not easily go down. This is because old but popular content comes to the top of the search, and another person who sees it creates a new content, creating a cycle. Therefore, ** In 2021, it is in a distorted state that venv is used for official content and venv is rarely used for informal content **.

Reason 3. Because pip can be used

Now that machine learning is in vogue, there are more opportunities to install additional libraries. At that time, the library installation example is described in pip. Also, due to the popularity of machine learning, the number of cases using Juypter has increased significantly. Even with Jupyter, there are many examples of installing additional libraries with! Pip. In other words, the chances of being guided to use pip are increasing significantly.

Additional library installation by pip on Jupyter works on the environment where Jupyter is launched. Therefore, ** Jupyter should be launched from the venv environment **, and Jupyter who wants to use another library set should also separate the base venv environment. This fact does not seem to be well recognized.

On the other hand, there are frequent accidents in which anaconda users see these as they are and install packages on anaconda with pip to make the system unstable (based on the sense value of QA trends in teratail). Masu).

Of course venv can use pip as it is, so there is no such problem. With more opportunities to use pip, ** there is no reason not to use venv now **.

Bonus. More virtual environments that satisfy three reasons

In fact, there are still virtual environments that satisfy these three reasons. Strictly speaking, it's not a "Python virtual environment". Therefore, Reason 1 is true as a proposition. This is because the precondition "being a Python virtual environment" is false as a proposition, so "because it is a Python virtual environment but being official" is true regardless of whether it is official or not.

One is Docker. It is a method of running raw Python on Docker and switching between container environments. In the book "Self-propelled programmer", it is stated that venv or Docker is the virtual environment of choice for professionals.

The other is Google Colab. It is a set that provides Jupyter + Ubuntu + VM in the cloud. The libraries that can be used for machine learning are pre-installed, and additional libraries can be installed with pip. Although there are different tastes, the environment such as additional libraries will be reset after the maximum usage time of the VM, so it can be used as if it were a virtual environment. An increasing number of educational courses are based on Google Colab.

In any case, ** "There is no reason not to use venv in Python virtual environments now" is a true proposition **.

Recommended Posts

Python virtual environment in 2021 ~ There is no reason not to use venv now ~
There is no switch in python
How to use is and == in Python
How to create a Python virtual environment (venv)
Use os.getenv to get environment variables in Python
virtual environment in python
venv: Python virtual environment management
How to use VS Code in venv environment on windows
[Introduction to Udemy Python 3 + Application] 36. How to use In and Not
How to develop in a virtual environment of Python [Memo]
What to do when there is no response due to Proxy setting in Python web scraping
Use fabric as is in python (fabric3)
How to use SQLite in Python
How to use ChemSpider in Python
How to use PubChem in Python
How to use the asterisk (*) in Python. Maybe this is all? ..
From installing Ansible to building a Python environment in Vagrant's virtual environment
When you want to use multiple versions of the same Python library (virtual environment using venv)
[Introduction to Python] How to use class in Python?
What to do if there is a decimal in python json .dumps
How to access environment variables in Python
Method to build Python environment in Xcode 6
Using venv in Windows + Docker environment [Python]
Migration from Python2 to Python3 (Python2 is rebuilt as a virtual environment and coexists)
Easy way to use Wikipedia in Python
To reference environment variables in Python in Blender
How to use __slots__ in Python class
How to use regular expressions in Python
Python environment preparation (venv first time use)
Add a Python virtual environment to VSCode
I want to use Python in the environment of pyenv + pipenv on Windows 10
Tips for those who are wondering how to use is and == in Python
How to use the C library in Python
Ubuntu18.04.05 Creating a python virtual environment in LTS
How to use Python Image Library in python3 series
Create a virtual environment with conda in Python
Use cryptography module to handle OpenSSL in Python
Use Python in your environment from Win Automation
How to use tkinter with python in pyenv
Work in a virtual environment with Python virtualenv.
Use Python in Anaconda environment with VS Code
From Python environment construction to virtual environment construction with anaconda
Use pydantic when reading environment variables in Python
python> How to write multiple lines> How to write in mnist_with_summaries.py> It seems that there is no need for line concatenation symbols
How to use a library that is not originally included in Google App Engine
What to do if the progress bar is not displayed in tqdm of python
What to do if Python IntelliSense is not displayed in VS Code on Windows
[For beginners] How to use say command in python!
Periodically execute python script with cron in venv environment
Python: Creating a virtual environment (venv), starting and stopping
How to run python in virtual space (for MacOS)
Use the CASA Toolkit in your own Python environment
Simplified Path input when enabling virtual environment in venv
Build a Python virtual environment using venv (Django + MySQL ①)
Building and enabling a python virtual environment, etc. (venv)
I tried to summarize how to use pandas in python
How to use the model learned in Lobe in Python
Re: Python lambda is useless ^ H ^ H ^ H ^ H ^ H Difficult to use
Setting up Jupyter Lab in a Python 3.9 venv environment
I want to use the R dataset in python
Use Heroku in python to notify Slack when a specific word is muttered on Twitter