I stumbled upon building a Python environment on a Mac, so make a note.
To write from the conclusion first, the reason why it didn't work was because I was editing bash without knowing that MacOS became Catalina and the default shell changed from bash
to zsh
.
Until now, I was careful because I should have written the environment variables of pyenv to .bash_profile
and .bashrc
and sourced them.
It was said that technology is constantly updated, but if you do not update your knowledge, it may fail.
Then, I will describe what I actually did below.
https://www.anaconda.com/distribution/ From here, download python3.7 and unpack the package
When will Apply change the default python to 3 series?
Check the python version with $ python --version
.
If it is a mac, 2.7 is probably included as standard, so switch.
For that, put pyenv. So, in order to put pyenb, put Homebrew.
Install brew https://brew.sh/index_ja
Install pyenv with brew
$ brew install pyenv
And here is where the problem stumbled.
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
Write the above in ~ / .zshrc
. ← (When Mac OS is Catalina or higher)
If the default shell is still bash, OS before Catalina, write to ~ / .bash_profile
.
Execute $ source ~ / .zshrc
or $ source ~ / .bash_profile
Check the environment variable PATH with $ echo $ PATH
This time, install 3.7.0. Please change the version to 3.7.4 etc. if necessary.
$ pyenv install 3.7.0
Is OK.
$ python --version
Python 2.7.16
As it is still python2, switch to python3.
$ pyenv gloval 3.7.0
$ python --version
Python 3.7.0
Is OK! If this does not switch, restart the terminal once and try again.
$ pyenv install anaconda3-5.3.1
I put the latest at this time.
Check the version with $ pyenv install list
.
As it is, the conda command cannot be used, so switch to anaconda.
$ pyenv global anaconda3-5.3.1
$ pyenv versions
system
* 3.7.0 (set by /Users/User name/.python-version)
anaconda3-5.3.1
That hasn't switched. Also, I stumbled here. The cause seems to be that the file .python-version exists here. So
$ rm ~/.python-version
$ pyenv versions
system
3.7.0
* anaconda3-5.3.1 (set by /Users/User name/.pyenv/version)
This completes the switch.
Recently, it seems that Jupyterlab is already installed in anaconda, so you don't have to bother to install it.
$ jupyter lab
Then it will start.
Recommended Posts