Building and enabling a python virtual environment, etc. (venv)

Overview

Make a note of how to create a virtual environment with python, how to enter (activate) the virtual environment, how to exit, etc. When I create a web application with python and deploy it, I write a library with reqirements.txt, but it is one of the causes that it becomes heavy if there is a library that is not used in the application. In such a case, use a virtual environment.

The activation method is slightly different for Windows and Mac.

Preparation

Prepare a folder to create a virtual environment. This time, assuming that Desktop has a folder called test, create a virtual environment here.

Create virtual environment

Open Anaconda Prompt for Windows or Terminal for Mac and set the test folder to the current directory. In this state

python -m venv venv

And press Enter. This will create a folder named venv. This folder is the virtual environment. Virtual environments that are no longer needed can be destroyed by deleting this folder.

Enable virtual environment

On windows

venv¥Scripts¥activate.bat

On Mac

source venv/bin/activate

You can enable it with. When you run this command, (base) becomes (venv). If this happens, you are in a virtual environment.

Install the required libraries in (venv) state (pip, conda, etc.)

Exit the virtual environment

deactive

Just hit.

that's all.

Recommended Posts

Building and enabling a python virtual environment, etc. (venv)
Building a Python virtual environment
Building a Python virtual environment
Python: Creating a virtual environment (venv), starting and stopping
Building a virtual environment with Python 3
How to create a Python virtual environment (venv)
[Python] Web development preparation (building a virtual environment)
Build a virtual environment with pyenv and venv
[Venv] Create a python virtual environment on Ubuntu
venv: Python virtual environment management
python standard virtual environment venv
Building a Docker working environment for R and Python
Build a Python virtual environment using venv (Django + MySQL ①)
Build a python virtual environment with virtualenv and virtualenvwrapper
Building a Python environment on Mac
Building a Python environment on Ubuntu
Create a virtual environment with Python!
Building a Python environment on a Mac and using Jupyter lab
[Python] Building a virtual python environment for the pyramid tutorial (summary)
[Pyenv] Building a python environment with ubuntu 16.04
Building a Python3 environment with Amazon Linux2
Building a Docker working environment for R and Python 2: Japanese support
Python virtual environment and packages on Ubuntu
Building a virtual environment using homebrew + pyenv-virtualenv
Let's create a virtual environment for Python
[Python] Create a virtual environment with Anaconda
Building a Python 3.6 environment with Windows + PowerShell
From installing Ansible to building a Python environment in Vagrant's virtual environment
Build a python virtual environment with pyenv
Building a Python development environment for AI development
Add a Python virtual environment to VSCode
Building a virtual environment for Mayavi dedicated to Python 3.6, Anaconda, Spyder users
Prepare a Python virtual environment for your project with venv with VS Code
Migration from Python2 to Python3 (Python2 is rebuilt as a virtual environment and coexists)
Python virtual environment construction (2017 version) pyenv and pyenv-virtualenv and virtualenv and virtualenv wrapper and pyvenv and venv
Ubuntu18.04.05 Creating a python virtual environment in LTS
Building a Python environment with WLS2 + Anaconda + PyCharm
ffmpeg-Build a python environment and split the video
Create a virtual environment with conda in Python
Build a simple Python virtual environment without pyenv
Think about building a Python 3 environment in a Mac environment
Work in a virtual environment with Python virtualenv.
Procedure for creating a Python quarantine environment (venv environment)
Use jupyter-lab installed in python virtual environment (venv)
Building a Python environment on a Sakura VPS server
Create a Python virtual development environment on Windows
python virtual environment Pipenv
virtual environment in python
Create a Python environment
Python3, venv and Ansible
Virtual environment with Python 3.6
A memo to create a virtual environment (venv) before Django
Write about building a Python environment for writing Qiita Qiita
Recommendation of building a portable Python environment with conda
Procedure for building a CDK environment on Windows (Python)
python package dependencies and virtual environment management tool Poetry
conda memorandum: Building a Python environment with supercomputer ITO
Building a Python environment for programming beginners (Mac OS)
Create a decent shell and python environment on Windows
Memo for building a machine learning environment using Python
Setting up Jupyter Lab in a Python 3.9 venv environment