I will explain how to build an environment using'venv', which is a lightweight module of python. By developing using a virtual environment, the library package used in the project is clarified. If you develop locally, there are cases where extra libraries and previously used libraries remain in the local environment and it does not work well when deployed to other machines, so create a project using a virtual machine etc. If you develop in it, the libraries and packages to be used will be clear, and it will be easier to share when developing on other machines or teams.
It is assumed that python3 series is installed.
For mac
# Create virtual environment
$ python3 -m venv name # nema: environment name
# Enable virtual environment
$ source venv/bin/activate
# Disable virtual environment
$ deactivate
# Create virtual environment
$ python -m venv name # nema: environment name
# Enable virtual environment
$ source venv/Script/activate
# Disable virtual environment
$ deactivate
From here, it's the same as installing locally.
For example, to install'numpy', do as follows.
(venv)$ pip3 install numpy
(venv)$ pip3 list
(venv)$ pip3 uninstall numpy
By using the configuration file [requirements.txt], you can perform version control and batch installation of installed Liplary packages. By using this configuration file, you can save the trouble of installing the library one by one.
(venv)$ pip3 freeze > requirements.txt
A'.txt' file is created in the executed directory.
(venv)$ pip3 install -r requirements.txt
By this execution, all the packages described in the configuration file can be installed.
Requirements without Version Specifiers ######
numpy
pandas
Requirements with Version Specifiers ######
numpy === 1.14.1
pandas === 0.22.0
This time, I briefly summarized the virtual environment'venv', but there are various other virtual environments. For example, pyenv, conda From now on, I hope it will be useful when developing python. .. ..
Recommended Posts