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.
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 **
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
[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
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 |
I want to manage multiple python versions Let's challenge pipenv.
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