How to develop in a virtual environment of Python [Memo]

While considering the development rules in Python, I learned how to build a virtual environment in Python, so I will write it down for myself. A Python virtual environment is an environment that is separated by installed modules, packages, and versions. I've been developing locally or on a virtual machine so far, but it seems that I can prepare a clean Python environment without using a virtual machine. Build a Python virtual environment using software called venv.

Creating a virtual environment

First of all, create a virtual environment. You can easily create a virtual environment by executing the following command on the terminal. When this command is executed, a directory called'environment name'is created under the executed directory, and that is the virtual environment. However, just entering the directory will not work and you will need to activate it.

Terminal


Uesr$ python3 -m venv 'The name of the environment'

Enable virtual environment

You can activate the virtual environment by actually moving to the directory and entering the following command. When enabled, the terminal $ and computer name will be preceded by ('environment name').

Terminal


User$ cd 'The name of the environment'
User$ source bin/activate
('The name of the environment') User$ 

End of virtual environment

Enter the following command to end the virtual environment. Doing this will revert to the display before activation.

Terminal


('The name of the environment') User$ deactivate
User$

Summary

I often install various libraries when developing Python, but if I do it locally, it will be difficult to manage the libraries, so I will actively use the virtual environment from now on. It's easy to create an environment, so please try it out.

Recommended Posts

How to develop in a virtual environment of Python [Memo]
How to create a Python virtual environment (venv)
How to develop in Python
How to build a new python virtual environment on Ubuntu
A note on how to load a virtual environment in PyCharm
How to get a list of built-in exceptions in python
Overview of Python virtual environment and how to create it
How to access environment variables in Python
Add a Python virtual environment to VSCode
How to determine the existence of a selenium element in Python
How to check the memory size of a variable in Python
How to check the memory size of a dictionary in Python
From installing Ansible to building a Python environment in Vagrant's virtual environment
virtual environment in python
How to share a virtual environment [About requirements.txt]
How to clear tuples in a list (Python)
Ubuntu18.04.05 Creating a python virtual environment in LTS
How to embed a variable in a python string
Summary of how to import files in Python 3
How to create a JSON file in Python
Create a virtual environment with conda in Python
Summary of how to use MNIST in Python
Steps to develop a web application in Python
How to notify a Discord channel in Python
Work in a virtual environment with Python virtualenv.
[Python] How to draw a histogram in Matplotlib
How to send a visualization image of data created in Python to Typetalk
[Python] How to put any number of standard inputs in a list
How to install python package in local environment as a general user
How to format a list of dictionaries (or instances) well in Python
Building a Python virtual environment
Building a Python virtual environment
A memo to create a virtual environment (venv) before Django
How to convert / restore a string with [] in python
A memo connected to HiveServer2 of EMR with python
A memo of how to use AIST supercomputer ABCI
How to set up a Python environment using pyenv
How to run python in virtual space (for MacOS)
[Python] How to expand variables in a character string
How to write a list / dictionary type of Python3
How to build a Django (python) environment on docker
How to execute a command using subprocess in Python
How to build a Python environment on amazon linux 2
How to pass the execution result of a shell command in a list in Python
How to get a list of files in the same directory with python
How to write a Python class
[Python] How to do PCA in Python
A memo on how to easily prepare a Linux exercise environment
[Python] How to make a list of character strings character by character
How to collect images in Python
How to shuffle a part of a Python list (at random.shuffle)
[Personal memo] Python virtual environment command memo
A story about how to specify a relative path in python.
How to use the __call__ method in a Python class
How to identify the element with the smallest number of characters in a Python list?
How to use SQLite in Python
How to import a file anywhere you like in Python
Create a virtual environment with Python!
How to create a virtual bridge
Building a virtual environment with Python 3
A standard way to develop and distribute packages in Python