Install Python3 on Mac and build environment [Definitive Edition]

How to install Python3 on Mac and build an environment </ strong>

Python2 series is installed on Mac by default, but here we will explain how to install 3 series with brew and how to build a virtual environment with venv.

Python3 installation procedure

Install Python3 with homebrew.

Homebrew installation

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Install Python3

Previously it was necessary to explicitly specify python3, but now it seems that 3 series is installed by default

brew install python

Check Python3

Execute the following, and if Python 3.7.3 etc. is displayed, the installation is successful. Also, python should select the 2nd series, and python3 should select the 3rd series.

python3 -V
  • As of May 10, 2020 3.7.3

Building a virtual environment with venv

Make directory and then change directory

mkdir project
cd project

Virtual environment cutout by venv

python3 -m venv env

Enable virtual environment

You can enable the virtual environment with the following command.

source env/bin/activate

With the virtual environment enabled, python -V is used to link the 3 systems.

Get out of the virtual environment

You can get out of the virtual environment with the following command.

deactivate

Summary

If you install Python3 and the library to be used differs depending on the project, it is essential to isolate the environment with venv by the above procedure. By using venv, it is possible to prevent unnecessary libraries from being mixed in when writing out the list of libraries used in the project with pip freeze> requirements.txt etc.


Previously, this article introduced the method using virtualenv instead of venv, so I will also describe it.

Environment construction by virtualenv

Install virtualenv with pip3.

Install virtualenv

pip3 install virtualenv
  • Please note that pip3 is used instead of pip.

Cut out a Python3 virtual environment

After moving to the project directory

virtualenv --python=/usr/local/bin/python3 env

Activate virtual environment

Run the following in the project directory

source env/bin/activate

Recommended Posts

Install Python3 on Mac and build environment [Definitive Edition]
Build Python3 and OpenCV environment on Ubuntu 18.04
Build Python environment with Anaconda on Mac
Install Python on Mac
Install Python 3 on Mac
Install Python 3.4 on Mac
How to build a beautiful Python environment on a new Mac and install Jupter Notebook
Build a Python environment on your Mac with Anaconda and PyCharm
Build a Python environment on Mac (Mountain Lion)
Build a Python development environment on your Mac
Install pygame on python3.4 on mac
[Definitive Edition] Building an environment for learning "machine learning" using Python on Mac
Build Python environment on Windows
Install pandas 0.14 on python3.4 [on Mac]
Try to build python and anaconda environment on Mac (by pyenv, conda)
Build python environment on windows
Install Python venv --VSCode --GitHub integration environment on Mac
Install selenium on Mac and try it with python
Build a machine learning Python environment on Mac OS
Build a Python development environment on Mac OS X
Build a Python environment on your Mac using pyenv
Install Python environment on local PC (pyenv, venv on Mac)
Building a Python environment on Mac
Install python2.7 on windows 32bit environment
Create a Python environment on Mac (2017/4)
Build and install OpenCV on Windows
Python environment construction memo on Mac
Install Python 3.7 Anaconda on MAC, but Python 2
Install python3 on Mac (El Capitan)
Environment construction of python3.8 on mac
Install Python development environment on Windows 10
Build Python 3.8 + Pipenv environment on Ubuntu 18.04
Steps to install python3 on mac
Build a python3 environment on CentOS7
Install LAMP on Amazon Linux 2 and build a WordPress environment.
Building a Python environment on a Mac and using Jupyter lab
Build a python data analysis environment on Mac (El Capitan)
Python 2.7, 3.4, 3.5 extension module build environment on Windows
Build a 64-bit Python 2.7 environment with TDM-GCC and MinGW-w64 on Windows 7
Build a python environment on MacOS (Catallina)
Python virtual environment and packages on Ubuntu
Create a python environment on your Mac
Steps to install Python environment on Ubuntu
Notes on building Python and pyenv on Mac
python on mac
Install lp_solve on Mac OS X and call it with python.
Install pyenv and Python 3.6.8 on Ubuntu 18.04 LTS
Build a Python + OpenCV environment on Cloud9
[Definitive Edition] Building an environment for learning "machine learning" using Python on Windows
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
Build Linux on a Windows environment. Steps to install Laradock and migrate
Python3 TensorFlow environment construction (Mac and pyenv virtualenv)
Install and run Python3.5 + NumPy + SciPy on Windows 10
Build python environment with pyenv on EC2 (ubuntu)
Build Python3.5 + matplotlib environment on Ubuntu 12 using Anaconda
Simply build a Python 3 execution environment on Windows
Install python package in personal environment on Ubuntu
Build a python environment with ansible on centos6
Install OpenCV 4.0 and Python 3.7 on Windows 10 with Anaconda
Build Python3 + flask environment on GCP Compute Engine