Build a Python development environment on Mac OS X

Installation of pyenv virtualenv virtualenvwrapper

.bash


$ brew install pyenv pyenv-virtualenv pyenv-virtualenvwrapper

Add the following to .zshrc

.bash


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

export PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV="true"
pyenv virtualenvwrapper

How to use pyenv

List of installable versions

.bash


$ pyenv install -l

Installation

.bash


$ pyenv install 3.4.1

Specifies the version used in the current shell

.bash


$ pyenv local 3.4.1

Specify the version to use by default

If not specified, system python will be used

.bash


$ pyenv global 3.4.1

When I open a new shell, it uses python set in global

.bash


$ python --version
Python 3.4.1

How to use mkvirtualenv

Environment creation

Contents of existing pip

.bash


$ pip list
argparse (1.2.2)
pbr (0.10.2)
pip (1.5.6)
setuptools (2.1)
six (1.8.0)
stevedore (1.1.0)
virtualenv (1.11.6)
virtualenv-clone (0.2.5)
virtualenvwrapper (4.3.1)

An environment is created with mkvirtualenv [environment name]

.bash


/Volumes/kobayashi/work% mkvirtualenv test
Using base prefix '/Users/kasei_san/.pyenv/versions/3.4.1'
New python executable in test/bin/python3.4
Also creating executable in test/bin/python
Installing setuptools, pip...done.

The environment name is displayed at the left end of the prompt (The contents of pip are cleared)

.bash


(test)/Volumes/kobayashi/work% pip list
pip (1.5.6)
setuptools (3.6)

Environment switching

.bash


$ workon testenv 

Environment list

.bash


$ workon 
test

Get out of the environment

.bash


$ deactivate

Delete environment

.bash


$ rmvirtualenv test

Move to the working directory after workon

Create an environment

.bash


$ mkvirtualenv playlist_to_mp3
Using base prefix '/Users/kasei_san/.pyenv/versions/3.4.1'
New python executable in playlist_to_mp3/bin/python3.4
Also creating executable in playlist_to_mp3/bin/python
Installing setuptools, pip...done.

Associate the current environment with the current directory with setvirtualenvproject

.bash


$ (playlist_to_mp3)/Users/kasei_san/Dropbox/work/playlist_to_mp3% setvirtualenvproject
Setting project for playlist_to_mp3 to /Users/kasei_san/Dropbox/work/playlist_to_mp3

Create an environment with a different version of python than global

.bash


$ pyenv local 2.7.9rc1
$ python --version
Python 2.7.9rc1

$ mkvirtualenv test

$ (test) python --version
Python 2.7.9rc1

Open a new shell

.bash


$ python --version
Python 3.4.1

$ workon test
$ (test) python --version
Python 2.7.9rc1

Confirm that the version changes

reference

Recommended Posts

Build a Python development environment on Mac OS X
Build a Python development environment on your Mac
Create a Python development environment on OS X Lion
Build a Python environment on Mac (Mountain Lion)
Build a Python development environment on Raspberry Pi
Continuation ・ Notes on preparing the Python development environment on Mac OS X
Building a Python environment on Mac
Build a GVim-based Python development environment on Windows 10 (3) GVim8.0 & Python3.6
Build a local development environment for Laravel6.X on Mac
Create a Python environment on Mac (2017/4)
Build a GVim-based Python development environment on Windows 10 (1) Installation
Build a Python environment on your Mac using pyenv
Build a Python development environment using pyenv on MacOS
Build a python3 environment on CentOS7
Create a Python development environment in 10 minutes (Mac OS X + Visual Studio Code)
Create a Python (pyenv / virtualenv) development environment on Mac (Homebrew)
Build a python data analysis environment on Mac (El Capitan)
Build a GVim-based Python development environment on Windows 10 (2) Basic settings
Build a python environment with pyenv (OS X El Capitan 10.11.3)
Mac OS X Mavericks 10.9.5 Development environment construction
Build a python environment on MacOS (Catallina)
Create a python environment on your Mac
Build Python environment with Anaconda on Mac
Mac OS X Yosemite 10.10 Development environment construction
Mac OS X development environment construction memo
Build a Python + OpenCV environment on Cloud9
Build a Python environment on your Mac with Anaconda and PyCharm
Simply build a Python 3 execution environment on Windows
Build a python environment with ansible on centos6
[Python] Build a Django development environment with Docker
Run Zookeeper x python (kazoo) on Mac OS X
Build a Kubernetes environment for development on Ubuntu
Mac OS X Mountain Lion 10.8.5 Development environment construction
Set up a Python development environment on Marvericks
Shpinx (Python documentation builder) on Mac OS X
Create a Python virtual development environment on Windows
Build Python environment on Windows
[Mac] Build a Python 3.x environment at the fastest speed using Docker
[ev3dev × Python] Build ev3dev development environment
Build python environment on windows
Memo on Mac OS X
Build a Python environment offline
I tried to build a Mac Python development environment with pythonz + direnv
Install Python3 on Mac and build environment [Definitive Edition]
# 2 Build a Python environment on AWS EC2 instance (ubuntu18.04)
Building an environment for "Tello_Video" on Mac OS X
Notes on creating a python development environment on macOS Catalina
Create a comfortable Python 3 (Anaconda) development environment on windows
How to build a Django (python) environment on docker
Build a machine learning application development environment with Python
How to build a development environment for TensorFlow (1.0.0) (Mac)
Building a Python environment for programming beginners (Mac OS)
How to build a Python environment on amazon linux 2
pangolin x python x mac os build failed memorandum unsolved
Build a machine learning environment natively on Windows 10 (x64)
Prepare Python development environment on Ubuntu
Building a Python environment on Ubuntu
Install Sphinx on Mac OS X
Python development environment construction on macOS
Create a python environment on centos
Install mitmproxy on Mac OS X