Here's how to install pyenv as a Python environment on your Mac. Here, I will show you how to git clone from pyenv's github (https://github.com/pyenv/pyenv) and pass it through Path. We will also show you how to create a virtual environment with venv depending on the tool and system you want to run.
--You can use git command --The shell uses zsh.
According to the story of Japanese Python users, it is recommended to download and install from the official Python site (https://www.python.org). I will.
However, when actually using Python,
--I want to use the latest version of Python 3.7 at the time of development for what I developed before ――I want to use the latest version of Python 3.9
So, you will want to switch versions depending on what you move. Therefore, I would like to take the method of building the environment with pyenv and installing the required version.
--pyenv official website https://github.com/pyenv/pyenv
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
To get pyenv.
On the official website Because it is described as
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
And pass the Path.
continue, Because there is
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.zshrc
To execute.
Reboot the terminal or
source ~/.zshrc
Apply with.
pyenv versions
To list the environments installed by pyenv. I just installed pyenv, so
* system (set by /Users/*****/.pyenv/version)
I think that only one line is displayed.
To check the installable version
pyenv install --list
To execute.
pyenv install --list | grep -E "^ +\d.+\d+$"
Then you can narrow down only the versions that start with a number and end with a number.
3.7.8
3.7.9
3.8.0
3.8.1
3.8.2
3.8.3
3.8.4
3.8.5
3.8.6
3.9.0
Is displayed, so here, install the latest version of 3.9.0
.
pyenv install 3.9.0
After a while, the installation is complete and
Installed Python-3.9.0 to /Users/*****/.pyenv/versions/3.9.0
Is displayed. continue,
pyenv shell 3.9.0
Enable the version you just installed in
python -V
Check the Python version with.
Python 3.9.0
If the Python version is displayed like, it is successful.
python -m venv *****
Create a virtual environment with. The ***** part specifies the path of the directory where the virtual environment is created. For example, if you want to create an environment for studying 3.9.0
pyenv shell 3.9.0
python -m venv ~/.venv/3.9.0/study
You can also do something like
Next, if you want to enable the created virtual environment,
source ~/.venv/3.9.0/study/bin/activate
To do. Then the prompt
(study) *****@******** ~ %
It looks like.
Recommended Posts