How to make Python 3.x and 2.x coexist on Mac (I also included opencv as a bonus)

Thing you want to do

  1. Both versions should be installed independently without interfering with each other
  2. Easy version switching

procedure

1. Install pyenv

$ brew install pyenv

Then add the following to your environment variables: For example, if you are using zsh for your shell, add the following to ~ / .zshrc: If you use bash, add it to ~ / .bash_profile.

~/.bash_profile


export PATH="$PYENV_ROOT/bin:$PATH"
export PYENV_ROOT="$HOME/.pyenv"
eval "$(pyenv init -)"

2. Install anaconda

python3 series installation

$ pyenv install anaconda3-x.x.x

python2 series installation

$ pyenv install anaconda2-x.x.x

pyenv global and pyenv local

You can switch the version with pyenv global hogehoge or pyenv local hugahuga. If you set it to global, the version change will be reflected as a whole, and if you set it to local, the version switching will be reflected under the current directory.

3 Install OpenCV

Python3 + OpenCV3 $ conda install -c https://conda.anaconda.org/menpo opencv3 Python2 + OpenCV2 $ conda install -c menpo opencv=2.4.11

afterwards $ pyenv rehash

To make sure it's installed properly, start Python and run the following code.

import cv2 cv2.__version__

Recommended Posts

How to make Python 3.x and 2.x coexist on Mac (I also included opencv as a bonus)
How to erase Python 2.x on Mac.
How to build a beautiful Python environment on a new Mac and install Jupter Notebook
How to install OpenCV on Mac
How to install OpenCV on Cloud9 and run it in Python
I tried to make a periodical process with Selenium and Python
[Python] How to make a class iterable
I want to make a web application using React and Python flask
How to install OpenCV on Jetson Nano Python
I want to make a game with Python
I read "How to make a hacking lab"
[Blender x Python] How to make an animation
[Blender x Python] How to make vertex animation
[Python] How to install OpenCV on Anaconda [Windows]
I tried to make a periodical process with CentOS7, Selenium, Python and Chrome
Suddenly I needed to work on a project using Python and Pyramid, so a note of how I'm studying
I made a program to convert images into ASCII art with Python and OpenCV
[Mac] I want to make a simple HTTP server that runs CGI with Python
How to build a Django (python) environment on docker
Build a Python development environment on Mac OS X
How to create a Python 3.6.0 environment by putting pyenv on Amazon Linux and Ubuntu
How to make a Python package using VS Code
[Python] I want to make a nested list a tuple
I want to AWS Lambda with Python on Mac!
A Python beginner made a chat bot, so I tried to summarize how to make it.
Steps to quickly create a deep learning environment on Mac with TensorFlow and OpenCV
How to build a Python environment on amazon linux 2
How to build a Python virtual execution environment using Visual Studio Code and pipenv on a Windows machine (also Jupyter notebook)
I want to set up a GUI development environment with Python or Golang on Mac
I also tried to imitate the function monad and State monad with a generator in Python
I want to make a voice changer using Python and SPTK with reference to a famous site
How to use Fujifilm X-T3 as a webcam on Ubuntu 20.04
How to build a new python virtual environment on Ubuntu
Building a Python environment on a Mac and using Jupyter lab
How to make a multiplayer online action game on Slack
How to make a Python package (written for an intern)
I tried "How to get a method decorated in Python"
How to register a package on PyPI (as of September 2017)
I tried to make a stopwatch using tkinter in python
How to write a metaclass that supports both python2 and python3
I tried to make GUI tic-tac-toe with Python and Tkinter
How to install Theano on Mac OS X with homebrew
I want to make input () a nice complement in python
Update python on Mac to 3.7-> 3.8
[Python] How to scrape a local html file and output it as CSV using Beautiful Soup
I tried to find out the difference between A + = B and A = A + B in Python, so make a note
[Python] I tried to make a simple program that works on the command line using argparse.
[5th] I tried to make a certain authenticator-like tool with python
How to rebuild python environment from pyenv on Mac environment (El Capitan)
[2nd] I tried to make a certain authenticator-like tool with python
I tried to make a regular expression of "amount" using Python
Build a Python environment on your Mac with Anaconda and PyCharm
[Python] I tried to implement stable sorting, so make a note
[Python] How to add rows and columns to a table (pandas DataFrame)
Make a simple OMR (mark sheet reader) with Python and OpenCV
Quickly install OpenCV 2.4 (+ python) on OS X and try the sample
I want to know if you install Python on Mac ・ Iroha
I tried to make a regular expression of "date" using Python
How to run Jupyter and Spark on Mac with minimal settings
How to build a Python environment using Virtualenv on Ubuntu 18.04 LTS
[C language] How to create, avoid, and make a zombie process