Since support for python2 will end in the end of 2019, we decided to introduce pyenv, which allows you to easily switch between python versions. However, I stumbled a little on version switching with pyenv, so I will summarize the main reasons why version switching is not possible. Article about the end of support for python2 https://news.mynavi.jp/article/20191118-924132/
MacOS Catalina 10.15.2 Homebrew 2.2.2 pyenv 1.2.16
I installed it with homebrew to install pyenv as follows.
Install pyenv
$ brew install pyenv
The installation was completed successfully, and I thought about installing python3.7.6 with pyenv, but for some reason I was told that pyenv does not exist. Normally, when installing with homebrew, a symbolic link is automatically created in / usr / local / bin
and the path passes, but at that time the path did not pass for some reason.
Apparently it was because I removed the old version of pyenv that was pre-installed or the link wasn't automatically posted.
Therefore, when I re-pasted the link with the homebrew command, the path of pyenv is now passed.
Paste link with brew
$ brew link pyenv
$ pyenv --version
pyenv 1.2.16
Then I installed python3 with pyenv and changed the version from 2 to 3.
When I checked the version with the pyenv command, it was 3.7.6
, but when I checked the version with the python command, it was 2.7.16
, and for some reason I could not change the version.
python version change
$ python --version
Python 2.7.16
#Check the version that can be installed
$ pyenv install --list
Available versions:
2.1.3
2.2.3
2.3.7
2.4.0
2.4.1
2.4.2
・ ・ ・
# python3.7.Install 6
$ pyenv install 3.7.6
#Check the installed version
$ pyenv versions
* system
3.7.6
#Version 3.7.Change to 6
$ pyenv global 3.7.6
$ pyenv versions
system
* 3.7.6
#Check version
$ python --version
Python 2.7.16
So I checked the path that the python command is looking at.
Then the destination was / usr / bin / python
.
If you want to use python, which is versioned with pyenv,
I had to change the destination path of the command to ~ / .pyenv / shims / python
.
Change the destination path of python commands
$ which python
/usr/bin/python
$ eval "$(pyenv init -)"
$ which python
~/.pyenv/shims/python
$ python --version
Python 3.7.6
I was able to change the version safely.
Through this python version change work, I felt that version control of programming languages was unexpectedly troublesome. However, all programming languages, not just python, are frequently upgraded. And any content needs to be maintained and adapted to the new version as the version changes. With that in mind, I felt that I needed a tool like pyenv that could easily change the version. When creating new content, it seems important to first consider a mechanism that allows you to easily manage the version of a programming language at the same time as installing the programming language.
How to install and use pyenv, what to do if you can't switch python versions https://qiita.com/koooooo/items/b21d87ffe2b56d0c589b [python] Understand how pyenv switches versions https://akamist.com/blog/archives/2610 About link in Homebrew https://hacknote.jp/archives/23816/
Recommended Posts