Create a python environment on your Mac

Use pyenv and virtualenv on Mac to build a python development environment that can switch versions and installation libraries.

Install pyenv

Install pyenv and virtualenv with homebrew. (I referred to here.)

pyenv / virtualenv installation


$ brew install pyenv
$ brew install pyenv-virtualenv

Put the path in .bash_profile.

.bash_profile


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

python installation

Install python with pyenv.

python install


$ pyenv install 3.6.2

If an error occurs here, try executing the following command.

Command to try when python installation error


$ xcode-select --install

Now try installing python again. If it doesn't work, ask Google teacher ... (sweat)

Switch python version

In the case of mac, python 2.7 is installed, so switch to 3.6.2 with this installed.

From python version confirmation to switching


$ pyenv versions
* system
  3.6.2
$ pyenv global 3.6.2
$ pyenv versions
  system
* 3.6.2 (set by ・ ・ ・ ・)
$ python -V
Python 3.6.2

Create an environment to try

Build an environment as a trial.

Create an environment with virtualenv


$ mkdir project1
$ cd project1
$ pyenv virtualenv 3.6.2 project1
$ pyenv local project1
(project1) $

When the environment changes, the environment will be displayed before the prompt. The part of (project1). When there is nothing, system is selected.

If you move from the created directory, you can see that the environment changes.

Environmental change confirmation


(project1) $ cd ..
$ cd project1
(project1) $

reference

Python environment construction on Mac (pyenv, virtualenv, anaconda, ipython notebook)

Recommended Posts

Create a python environment on your Mac
Create a Python environment on Mac (2017/4)
Build a Python development environment on your Mac
Building a Python environment on Mac
Create a python environment on centos
Build a Python environment on your Mac using pyenv
Create a Python environment
Create a Python (pyenv / virtualenv) development environment on Mac (Homebrew)
Create a virtual environment for python on mac [Very easy]
Build a Python environment on your Mac with Anaconda and PyCharm
Build a Python environment on Mac (Mountain Lion)
[Venv] Create a python virtual environment on Ubuntu
Create a Python execution environment on IBM i
Create a Python virtual development environment on Windows
Create a Python3 environment with pyenv on Mac and display a NetworkX graph
Build a machine learning Python environment on Mac OS
Create a comfortable Python 3 (Anaconda) development environment on windows
Build a Python development environment on Mac OS X
Create a decent shell and python environment on Windows
Create a Python development environment on OS X Lion
Create a virtual environment with Python!
Python environment construction memo on Mac
Create a Linux environment on Windows 10
Environment construction of python3.8 on mac
Build a python3 environment on CentOS7
python on mac
Building a Python environment on a Mac and using Jupyter lab
Build a python data analysis environment on Mac (El Capitan)
Build a python environment on CentOS 7.7 for your home server
Build a python environment on MacOS (Catallina)
Let's create a virtual environment for Python
[Python] Create a virtual environment with Anaconda
[Python] Create a Batch environment using AWS-CDK
[Mac] Building a virtual environment for Python
Creating a python virtual environment on Windows
I installed Kivy on a Mac environment
Build Python environment with Anaconda on Mac
Create an OpenCV3 + python3 environment on OSX
Build a Python + OpenCV environment on Cloud9
Create a Python environment for professionals in VS Code on Windows
[Mac] Create a Python3 execution environment from the fully initialized state
Create a Python module
Install Python on Mac
Install Python 3 on Mac
Install Python 3.4 on Mac
Mac environment construction Python
Build a LAMP environment on your local Docker
Create a Vim + Python test environment in 1 minute
How to create a Python virtual environment (venv)
Simply build a Python 3 execution environment on Windows
Build a python environment with ansible on centos6
Create a virtual environment with conda in Python
Create a python3 build environment with Sublime Text3
Think about building a Python 3 environment in a Mac environment
Set up a Python development environment on Marvericks
Create a Mac app using py2app and Python3! !!
Building a Python environment on a Sakura VPS server
[Docker] Create a jupyterLab (python) environment in 3 minutes!
[Note] How to create a Mac development environment
Build a Python development environment on Raspberry Pi
Things to watch out for when creating a Python environment on a Mac