How to create a Python virtual environment (venv)

When I started learning Python and was thinking about creating an app, it seems that it is common to create a virtual environment, so I will summarize the operation method.

Why you need a virtual environment

The reason why we need a virtual environment in the first place is to make it possible to use the appropriate version of the library and Python for each application.

It wasn't necessary while I was just starting to learn Python and learning the basics such as grammar, but it seems better to use a virtual environment when I'm about to create more and more apps.

Basic knowledge of virtual environment

Conda for using Anaconda for data science is famous, and there seems to be many others such as virtualenv which is the base of venv, but here I will explain the Python standard ** venv **.

How to create a virtual environment

Since venv is a Python standard, just execute the following command in any directory. A folder is created with the entered virtual environment name.

python -m venv [Virtual environment name]

Modules can be specified by adding the **-m ** option to the python command. When specifying a module, specify only the module name and no extension (.py) is required.

Run virtual environment

After creating the virtual environment, move to the created folder and execute the following command.

For Windows scripts\activate

For Mac source bin/activate

If ** PSSecurityException ** occurs on Windows, execute the following command. set-executionpolicy remotesigned -scope process

Exit virtual environment

Note that the process may remain unless the virtual environment executed by activate is terminated. When you are done, use the deactivate command to deactivate the virtual environment and exit. deactivate

Initialize virtual environment

If you want to return to the initial state for some reason, move to the parent directory where the virtual environment was created and execute the following command. python -m venv --clear [Virtual environment name]

Delete virtual environment

Delete the created folder after deactivating it with deactivate. rm -rf [Virtual environment name]

Recommended Posts

How to create a Python virtual environment (venv)
[Venv] Create a python virtual environment on Ubuntu
Create a virtual environment with Python!
How to create a virtual bridge
A memo to create a virtual environment (venv) before Django
How to build a new python virtual environment on Ubuntu
Let's create a virtual environment for Python
[Python] Create a virtual environment with Anaconda
How to develop in a virtual environment of Python [Memo]
Create a Python environment
Add a Python virtual environment to VSCode
Overview of Python virtual environment and how to create it
How to share a virtual environment [About requirements.txt]
How to create a JSON file in Python
Create a virtual environment with conda in Python
[Note] How to create a Ruby development environment
Create a Python virtual development environment on Windows
[Note] How to create a Mac development environment
Building a Python virtual environment
venv: Python virtual environment management
python standard virtual environment venv
Building a Python virtual environment
Steps to create a Python virtual environment with VS Code on Windows
Python: Creating a virtual environment (venv), starting and stopping
How to set up a Python environment using pyenv
How to build a Django (python) environment on docker
Build a Python virtual environment using venv (Django + MySQL ①)
Building and enabling a python virtual environment, etc. (venv)
[Python] How to create a 2D histogram with Matplotlib
How to build a Python environment on amazon linux 2
How to create a kubernetes pod from python code
How to write a Python class
Create a Python environment on Mac (2017/4)
How to create a Conda package
When I tried to create a virtual environment with Python, it didn't work
Building a virtual environment with Python 3
Create a python environment on centos
How to create a Dockerfile (basic)
5 Ways to Create a Python Chatbot
How to create a config file
[Python] How to create a local web server environment with SimpleHTTPServer and CGIHTTPServer
[Python Kivy] How to create a simple pop up window
A note on how to load a virtual environment in PyCharm
How to build a python2.7 series development environment with Vagrant
Create a virtual environment for python on mac [Very easy]
How to create a Python 3.6.0 environment by putting pyenv on Amazon Linux and Ubuntu
How to create a clone from Github
How to access environment variables in Python
How to build a sphinx translation environment
How to create a git clone folder
[Python] How to make a class iterable
[Python] How to convert a 2D list to a 1D list
How to create an NVIDIA Docker environment
Create a python environment on your Mac
[Python] Create a Batch environment using AWS-CDK
I want to build a Python environment
[Python] How to invert a character string
How to prepare Python development environment [Mac]
[Mac] Building a virtual environment for Python
Creating a python virtual environment on Windows
How to get a stacktrace in python