python standard virtual environment venv

Prerequisite environment

venv

A virtual environment that has been installed as standard since python3.5. I'm really happy because I don't have to put anything else in it. Unfortunately, you can't specify the python version, the installed python version will be used. Can be used to switch libraries.

console

For Windows, there are bat for cmd and ps1 for powershell, and I tried it with cmd. ** Open cmd with administrator privileges because you need administrator privileges when adding a library with pip **

Create virtual environment

python -m venv [environment name]

D:\work> python -m venv mytestenv

Virtual environment folder structure(* Partially omitted)


mytestenv ・ ・ ・ Create a folder with the environment name
+ Scripts
  + activate
  + activate.bat ・ ・ ・ For Windows
  + Activate.ps1 ・ ・ ・ For Windows
  + django-admin.exe
  + django-admin.py
  + pip.exe
  + python.exe
+ Lib
  + site-packages ・ ・ ・ Enter here after adding the library
+ Include

Switch to virtual environment

[Environment name] \ Scripts \ activate.bat

D:\work> mytestenv\Scripts\activate.bat

Switched state


(mytestenv) D:\work>

Add library to try


(mytestenv) D:\work>pip list
Package    Version
---------- -------
pip        19.2.3
setuptools 41.2.0

(mytestenv) D:\work>pip install numpy
Collecting numpy
  Using cached https://files.pythonhosted.org/packages/69/89/d8fc61a51ded540bd4b8859510b4ae44a0762c8b61dd81eb2c36f5e853ef/numpy-1.19.2-cp38-cp38-win_amd64.whl
Installing collected packages: numpy
Successfully installed numpy-1.19.2

(mytestenv) D:\work>pip list
Package    Version
---------- -------
numpy      1.19.2
pip        19.2.3
setuptools 41.2.0

Other virtual environment

There are many, but only the ones that are likely to be used.

Virtual environment site
venv https://docs.python.org/ja/dev/tutorial/venv.html
virtualenv https://github.com/pypa/virtualenv
pipenv https://github.com/pypa/pipenv

in conclusion

I want to manage multiple python versions Let's challenge pipenv.

bonus

ps1 got a security error about script execution. (Try this separately)

powershell


D:\work> mytestenv\Scripts\Activate.ps1
mytestenv\Scripts\Activate.ps1 :Script execution is disabled on this system, so file D:\work\mytestenv\Scr
ipts\Activate.Unable to read ps1. For more information, see about_Execution_Policies」(https://go.microsoft.com/fwl
ink/?LinkID=135170)Please refer to.
Location line:One character:1
+ mytestenv\Scripts\Activate.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          :Security error: (: ) []、PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

Recommended Posts

python standard virtual environment venv
venv: Python virtual environment management
python virtual environment Pipenv
virtual environment in python
Virtual environment with Python 3.6
How to create a Python virtual environment (venv)
Building a Python virtual environment
Building a Python virtual environment
python3.8 venv environment jupyter notebook
Python: Creating a virtual environment (venv), starting and stopping
Build a Python virtual environment using venv (Django + MySQL ①)
Building and enabling a python virtual environment, etc. (venv)
venv (Python)
Virtual Environment Version Control Summary Python
[Personal memo] Python virtual environment command memo
Create a virtual environment with Python!
Python development environment for macOS using venv 2016
Using venv in Windows + Docker environment [Python]
Python environment construction
python environment settings
python windows environment
About the virtual environment of python version 3.7
[Python] Standard input
Let's create a virtual environment for Python
[Python] Create a virtual environment with Anaconda
Environment construction (python)
Beginner virtual environment
Effortlessly vscode + venv virtual environment (Windows) memo
[Mac] Building a virtual environment for Python
Creating a python virtual environment on Windows
python environment construction
Python environment construction
Build a python virtual environment with pyenv
python environment construction
Python environment preparation (venv first time use)
Add a Python virtual environment to VSCode
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
Python (Windows 10) Virtual Environment / Package with VS Code
Create a virtual environment with conda in Python
[Python] Web development preparation (building a virtual environment)
Build a simple Python virtual environment without pyenv
Build a virtual environment with pyenv and venv
[Node-RED] Execute Python on Anaconda virtual environment from Node-RED [Anaconda] [Python]
Work in a virtual environment with Python virtualenv.
Procedure for creating a Python quarantine environment (venv environment)
From Python environment construction to virtual environment construction with anaconda
Create a Python virtual development environment on Windows
[Python] Get environment variables
My python environment memo
Unification of Python environment
python windows environment construction
homebrew python environment construction
Python development environment construction
About Python development environment
Python environment with docker-compose
python2.7 development environment construction
Create a Python environment
Development environment in Python
[Python] About standard input
Python3, venv and Ansible