Building a virtual environment with Python 3

Introduction

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.

environment

Creating a virtual environment

# 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

Library installation

From here, it's the same as installing locally.

Library installation

For example, to install'numpy', do as follows.

(venv)$ pip3 install numpy

Check installed libraries

(venv)$ pip3 list

Delete library

(venv)$ pip3 uninstall numpy

Library package management

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.

File the installed library

(venv)$ pip3 freeze > requirements.txt

A'.txt' file is created in the executed directory.

Installation of configuration file

(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

Summary

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

Building a virtual environment with Python 3
Building a Python virtual environment
Building a Python virtual environment
Create a virtual environment with Python!
Virtual environment with Python 3.6
Building a Python3 environment with Amazon Linux2
[Python] Create a virtual environment with Anaconda
Building a Python 3.6 environment with Windows + PowerShell
[Mac] Building a virtual environment for Python
Build a python virtual environment with pyenv
Building a python environment with virtualenv and direnv
Building a Python environment with WLS2 + Anaconda + PyCharm
Create a virtual environment with conda in Python
[Python] Web development preparation (building a virtual environment)
Work in a virtual environment with Python virtualenv.
Building a kubernetes environment with ansible 2
Building a Python environment on Mac
Recommendation of building a portable Python environment with conda
Build a python virtual environment with virtualenv and virtualenvwrapper
Building a Python environment on Ubuntu
Building and enabling a python virtual environment, etc. (venv)
Build a python virtual environment with virtualenv and virtualenvwrapper
conda memorandum: Building a Python environment with supercomputer ITO
Building a kubernetes environment with ansible 1
[Python] Building a virtual python environment for the pyramid tutorial (summary)
Building a virtual environment with pyenv-virtualenv/Python (installation, environment settings, packages) Mac environment
[Python] Building an environment with Anaconda [Mac]
Let's create a virtual environment for Python
Creating a python virtual environment on Windows
Create a virtual environment with Python_Mac version
Build a modern Python environment with Neovim
Building a Python development environment for AI development
Add a Python virtual environment to VSCode
python virtual environment Pipenv
virtual environment in python
Python environment with docker-compose
Create a Python environment
From installing Ansible to building a Python environment in Vagrant's virtual environment
How to create a Python virtual environment (venv)
Ubuntu18.04.05 Creating a python virtual environment in LTS
Building an Anaconda environment for Python with pyenv
Python (Windows 10) Virtual Environment / Package with VS Code
Create a python3 build environment with Sublime Text3
[Memo] Build a virtual environment with Pyenv + anaconda
Build a simple Python virtual environment without pyenv
A memo when creating a python environment with miniconda
Build a virtual environment with pyenv and venv
Think about building a Python 3 environment in a Mac environment
[Venv] Create a python virtual environment on Ubuntu
Commands for creating a python3 environment with virtualenv
Flow of creating a virtual environment with Anaconda
Build a Python environment with OSX El capitan
Quickly build a Python Django environment with IntelliJ
Building a Python environment on a Sakura VPS server
From Python environment construction to virtual environment construction with anaconda
Create a Python virtual development environment on Windows
Build a Python machine learning environment with a container
Build a python execution environment with VS Code
Get a quick Python development environment with Poetry
Building a virtual environment for Mayavi dedicated to Python 3.6, Anaconda, Spyder users
Steps to create a Python virtual environment with VS Code on Windows