What A note about Python virtual environments and commands. There are many good articles that can be used as a reference, so make a note of the contents in your own environment. I hope it will be helpful to other people.
pyenv Multiple versions of Python can coexist. For example, install Python 3.8.3 and Python 3.7.2 on your PC and The default (global) is Python 3.7.2, but only certain directories should be Python 3.8.3. You can also say.
virtualenv You can build multiple environments with the same version of Python. For example Environment A has Python 3.7.2 + TensorFlow Environment B is Python 3.7.2 + Keras You can create such an environment individually.
venv A virtual environment program that comes standard with Python. I feel that virtualenv is easier to understand, such as command operations. (I personally use virtualenv instead of venv.)
conda Virtual environment program included in Anaconda (I can't talk much because of lack of learning. I will take another opportunity ...)
--There is a way to install pyenv after installing Homebrew --The following Progate tutorial site is useful -Prepare a Python development environment! (Mac) | Learn from the basics if you're an introduction to programming Progate --There is also a way to install by git clone -Python virtual environment | Building a Python development environment with pyenv and vertualenv
##Check the Python version that can be installed
pyenv install --list
##Installing a specific version of Python
pyenv install 3.7.2
##Checking the installed Python version
pyenv versions
# * system (set by /Users/username/.pyenv/version)
# 3.7.2
# 3.8.3
##The substance of the installed Python is~/.pyenv/versions/Saved under the directory
cd ~/.pyenv/versions
ls
# 3.7.2 3.8.3
##Specify the default Python version for PC-wide use
pyenv global 3.7.2
##pyenv versions command or python-You can check the version with the V command
pyenv versions
# system
# * 3.7.2 (set by /Users/username/.pyenv/version)
# 3.8.3
##How to change the Python version only for a specific directory (make it local)
cd ./sample
pyenv local 3.8.3
##pyenv verions command or python-You can check the version with the V command
python -V
# Python 3.8.3
##Delete virtual environment
pyenv uninstall 3.7.2
--Pip install is common Note: You can also install from pyenv (see below)
##How to install virtualenv
pip install virtualenv
##Creating and using a virtual environment (wherever you create it)
virtualenv ~/.virtualenvs/first-env
source ~/.virtualenvs/first-env/bin/activate
##Disable virtual environment
deactivate
##Delete virtual environment
rm -rf ~/.virtualenvs/first-env
--At the following site, virtualenv is installed from pyenv. It looks convenient.
-Python virtual environment | Building a Python development environment with pyenv and vertualenv
--However, in my environment where pyenv was installed using Homebrew, the command pyenv virtualenv 3.7.2 project_x
could not be executed. (pyenv: no such command `virtualenv')
--I will add it when the cause etc. are known.
Recommended Posts