How to change Python version

If you are new to Python and want to change the default version! I think it will be useful in such a case. It took a lot of time when I tried to change Python to 3 series.

Here, we will use a tool called pyenv. I think it is very convenient because you can easily switch to the 2nd system again.

First check the version

$ python -V
Python 2.7.10

Perform pyenv installation using Homebrew

$ brew update
#Update Homebrew
$ brew install pyenv
#Install pyenv

Select and install the required Python version

$ pyenv install --list
#Command to display a list of installable versions
$ pyenv install 3.5.6
#Perform Python installation

The installed version is displayed

$ pyenv versions
* system
  3.5.6 (set by $HOME/.pyenv/version)

Set global version

$ pyenv global 3.5.6
#Specify the global version

--But with python -V, the first version is still displayed

$ python -V
Python 2.7.10

--Execute eval "$ (pyenv init-)" to reflect the changes

$ eval "$(pyenv init -)"
#By running pyenv init,$HOME/.pyenv/version)Applies by adding the Path of the environment variable to the Path of the environment variable

Finally confirm

% python -V          
Python 3.5.6

You can change it at any time by selecting the version using the [pyenv global version] command. I don't know how eval "$ (pyenv init-)" works, so I have to learn more. .. It's very convenient, but I'm still not familiar with it, so I'd like to dig a little deeper.

Recommended Posts

How to change Python version
How to get the Python version
How to install Python
How to install python
How to check opencv version in python
[2020 version] How to install Python3 on AWS EC2
[Python] How to change the date format (display format)
Let's understand how to pass arguments (Python version)
How to specify TLS version in python requests
[2020.8 latest] How to install Python
How to install Python [Windows]
python3: How to use bottle (2)
Tabpy 1.0 (2020-01 version) How to install
[Python] How to use list 1
How to change Jupyter layout
How to update Python Tkinter to 8.6
Change python version using pyenv
Python: How to use pydub
[Python] How to use checkio
How to run Notepad ++ Python
How to develop in Python
[python] How to judge scalar
[Python] How to use input ()
How to use Python lambda
[Python] How to use virtualenv
python3: How to use bottle (3)
python3: How to use bottle
How to use Python bytes
How to auto-submit Microsoft Forms using python (Mac version)
[Work efficiency] How to change file names in Python
How to write a Python class
[Python] How to FFT mp3 data
[Python] How to do PCA in Python
Python: How to use async with
[Python] How to derive nCk (ABC156-D)
[Python] How to use Pandas Series
How to collect images in Python
[Introduction to Python] How to parse JSON
Change python default encoding to utf-8
[Ansible] How to prevent forced change
Change the Python version of Homebrew
How to get started with Python
[Python] How to import the library
How to use Mysql in python
How to use OpenPose's Python API
[Python] How to swap array values
How to wrap C in Python
How to use ChemSpider in Python
How to use FTP with Python
How to use PubChem in Python
How to speed up Python calculations
How to calculate date with python
How to access wikipedia from python
How to use python zip function
How to check Linux OS version
[Nanonets] How to post Memo [Python]
Python version to get unused ports
How to handle Japanese in Python
[Python] How to use Typetalk API
[AWS SAM] Introduction to Python version
[Python] Change the alphabet to numbers