Causes when python version cannot be changed using pyenv

background

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/

environment

MacOS Catalina 10.15.2 Homebrew 2.2.2 pyenv 1.2.16

Cause of not being able to change the version

1. The path of pyenv does not pass

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

2. I haven't changed the python command path

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.

Summary

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.

Reference material

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

Causes when python version cannot be changed using pyenv
Change python version using pyenv
[Python] Be careful when using print
"Temporary solution" when pip cannot be updated [Python]
Investigation when import cannot be done with python
Python version switching (pyenv)
A solution to the problem that the Python version in Conda cannot be changed
Python note: When the pip command cannot be used
Minimum memo when using Python on Mac (pyenv edition)
When USB cannot be formatted
When pydub cannot be installed
Options when installing libraries that cannot be piped with pyenv
Solution when the image cannot be displayed with tkinter [python]
Note links that may be useful when using Python, Selenium2
Scripts that can be used when using bottle in Python
List of libraries to install when installing Python using Pyenv
Precautions when using pit in Python
Introducing Python using pyenv on Ubuntu 20.04
[Python] Error and solution memo when using venv with pyenv + anaconda
Notes on installing Python using PyEnv
Install Python on CentOS using Pyenv
Precautions when using phantomjs from python
When using MeCab with virtualenv python
Install Python on CentOS using pyenv
Precautions when using six with Python 2.5
[VS Code] ~ Tips when using python ~
When using regular expressions in Python
Periodic execution processing when using tkinter [Python3]
What Rubyist should know when using pyenv
Favicon placement (when using Python, Flask, Heroku)
[python, multiprocessing] Behavior for exceptions when using multiprocessing
Python modules with "-(hyphen)" cannot be removed
Solution when aws-cli cannot be executed on Mac virtual environment (after installing Python 3.8)
Correspondence memo when the direction key cannot be used on the python command line
Project cannot be created with Python3.5 (Windows) + django1.7.1
When Html cannot be output with Jupyter Notebook
When contour map cannot be drawn with APLpy
[Linux] When "| (pipe)" cannot be hit on CentOS7
Install Python 3.8.6 on macOS Big Sur using pyenv
Python environment settings (virtualenv + pip cannot be done)
Character encoding when using csv module of python 2.7.3
PIL cannot be installed by virtualenv with pyenv
What are you using when testing with Python?
I get an error when I try to raise Python to 3 series using pyenv on Catalina