We have summarized the development environment construction when using Python on Windows.
By using a virtual environment, you can manage Python packages for each virtual environment.
- Up to Python 3.4, **
pyvenv
** was recommended, but as of Python 3.8,venv
** is recommended. (pyvenv
** is deprecated from Python 3.6)
PowerShell
# python -m venv Environment name to be created
python -m venv venv
--Execute at the project root (application root)
PowerShell
.\venv\Scripts\activate
* When PSSecurityException occurs *
The default execution policy of PowerShell restricts script execution of external files, so it is necessary to change the execution policy.
# -Scope Process :Apply only current process execution policy Set-ExecutionPolicy -Scope Process RemoteSigned
PowerShell
deactivate
Use pip (installer program) to manage PyPI (The Python Package Index) packages.
PowerShell
#pip install package name
pip install black
#pip install package name==version
pip install black==19.3b0
PowerShell
#pip uninstall package name
pip uninstall black
PowerShell
#View list of installed packages
pip list
#Output of installed package list
pip freeze > requirements.txt
#Bulk installation from the package list
pip install -r requirements.txt
* Notes on outputting files with PowerShell *
When redirect (>) is used in PowerShell, the character code of the output file is "UTF-16 LE". In order to output a file with "UTF-8", it is necessary to use the following cmdlet.
pip freeze | Out-File -Encoding utf8 requirements.txt
Recommended Posts