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).
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 **.
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 **.
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 **.
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