Building a Python environment on a Mac and using Jupyter lab

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.

1. Install Anaconda

https://www.anaconda.com/distribution/ From here, download python3.7 and unpack the package

When will Apply change the default python to 3 series?

2. Preparing to install python

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.

  1. Install brew https://brew.sh/index_ja

  2. Install pyenv with brew

    $ brew install pyenv
    
  3. 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.

  1. Execute $ source ~ / .zshrc or $ source ~ / .bash_profile

  2. Check the environment variable PATH with $ echo $ PATH

    echo_path.png

3. Install python

This time, install 3.7.0. Please change the version to 3.7.4 etc. if necessary.

$ pyenv install 3.7.0

Is OK.

4. Switching python

$ 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.

5. Install anaconda

$ pyenv install anaconda3-5.3.1

I put the latest at this time. Check the version with $ pyenv install list.

6. Switch to anaconda

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.

7. Start Jupyterlab

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

Building a Python environment on a Mac and using Jupyter lab
Building a Jupyter Lab development environment on WSL2 using Anaconda3
Build a Python environment on your Mac using pyenv
Building a Python environment on Ubuntu
Create a Python environment on Mac (2017/4)
Until building a Python development environment using pyenv on Ubuntu 20.04
Create a python environment on your Mac
[Mac] Building a virtual environment for Python
Notes on building Python and pyenv on Mac
Build a Python environment on your Mac with Anaconda and PyCharm
Building a python environment with virtualenv and direnv
Build a Python environment on Mac (Mountain Lion)
Build a Python development environment on your Mac
Think about building a Python 3 environment in a Mac environment
Create a Mac app using py2app and Python3! !!
Building a Python environment on a Sakura VPS server
[Definitive Edition] Building an environment for learning "machine learning" using Python on Mac
Notes on setting pyenv and python environment using Homebrew on Mac OS Marvericks
Create a Python3 environment with pyenv on Mac and display a NetworkX graph
Building a Python development environment on Windows -From installing Anaconda to linking Atom and Jupyter Notebook-
Building a Python virtual environment
Building a Python virtual environment
Install Python3 on Mac and build environment [Definitive Edition]
Build a Django development environment using pyenv-virtualenv on Mac
Building a Docker working environment for R and Python
Build a machine learning Python environment on Mac OS
Build a Python development environment on Mac OS X
Building and enabling a python virtual environment, etc. (venv)
Procedure for building a CDK environment on Windows (Python)
Build a Python development environment using pyenv on MacOS
Building a Python environment for programming beginners (Mac OS)
Create a decent shell and python environment on Windows
Memo for building a machine learning environment using Python
Setting up Jupyter Lab in a Python 3.9 venv environment
Create a Python (pyenv / virtualenv) development environment on Mac (Homebrew)
Error when building mac python environment
How to build a beautiful Python environment on a new Mac and install Jupter Notebook
Python environment construction memo on Mac
Building a virtual environment with Python 3
Build a python data analysis environment on Mac (El Capitan)
Create a python environment on centos
Environment construction of python3.8 on mac
Build a python3 environment on CentOS7
Create a virtual environment for python on mac [Very easy]
Build a Chainer environment using CUDA and cuDNN on a p2 instance
Building a Docker working environment for R and Python 2: Japanese support
Build a 64-bit Python 2.7 environment with TDM-GCC and MinGW-w64 on Windows 7
Build a game leaderboard on Alibaba cloud using Python and Redis
How to build a Python environment using Virtualenv on Ubuntu 18.04 LTS
A python script that deletes ._DS_Store and ._ * files created on Mac
Everything from building a Python environment to running it on Windows
[Pyenv] Building a python environment with ubuntu 16.04
Django Crispy Tutorial (Environment Building on Mac)
[Python] Building an environment with Anaconda [Mac]
Python virtual environment and packages on Ubuntu
Building a virtual environment using homebrew + pyenv-virtualenv
Building a LaTeX environment on Chrome OS
A memo with Python2.7 and Python3 on CentOS
Building a Python 3.6 environment with Windows + PowerShell
[Python] Create a Batch environment using AWS-CDK
Creating a python virtual environment on Windows