How to set up a Python environment using pyenv

It's the 15th day of the LIG Advent Calendar! Hello, this is Jack (@kazuhikoyamashita).

My recent hobby is doing matrix calculations in Python. This time, I would like to summarize the procedure for building a Python environment using pyenv.

Install pyenv

Execute the brew command

Execute the following command to install pyenv. It can be easily installed with the brew command.

% brew install pyenv

Add settings to .zprofile

Add the following settings to your .zprofile so that pyenv will run automatically when you start the terminal.

% echo 'if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi' >> ~/.zprofile

Reflect the settings

Use the source command to reflect the settings added to .zprofile. The command to reflect is as follows.

% source ~/.zprofile

Install python

Find out the Python version

Check the version of Python that comes standard with your Mac. To check the version, execute the following command. In my environment, I currently have Python 2.7.10.

% python --version
Python 2.7.10

This time, I will use pyenv to install the latest (as of December 15, 2015) Python 3.5.0.

Install Python 3.5.0

To install Python 3.5.0, execute the following command.

% pyenv install 3.5.0

If you want to install another version, you can check the installable version with the following command.

% pyenv install --list

Switching Python environment

To switch from the system Python environment to the Python environment installed by pyenv, execute the following command.

% pyenv global 3.5.0
% python --version
Python 3.5.0

You are now switched to Python 3.5.0.

I will actually move it

Follow the steps below to output "Hello, World!".

% python
Python 3.5.0 (default, Dec  9 2015, 17:22:19) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.72)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> string = 'Hello, World!'
>>> str(string)
'Hello, World!'

Next time, I would like to write an article on matrix calculation. that's all!

Recommended Posts

How to set up a Python environment using pyenv
How to set up SVM using Optuna
How to build a Python environment using Virtualenv on Ubuntu 18.04 LTS
How to create a Python virtual environment (venv)
How to set up Random forest using Optuna
How to set up Random forest using Optuna
How to set up a local development server
Set up a Python development environment on Marvericks
Try to set up a Vim test environment quite seriously (for Python)
How to build a Django (python) environment on docker
How to make a Python package using VS Code
Build a Python environment on your Mac using pyenv
Build a Python development environment using pyenv on MacOS
How to execute a command using subprocess in Python
How to set up and compile your Cython environment
How to build a Python environment on amazon linux 2
Set up a Python development environment with Sublime Text 2
A complete guidebook to using pyenv, pip and python in an offline environment
How to write a Python class
Set up Python environment on CentOS
How to speed up Python calculations
Set up a Python development environment with Visual Studio Code
How to build a new python virtual environment on Ubuntu
How to import Python library set up in EFS to Lambda
How to transpose a 2D array using only python [Note]
[Python Kivy] How to create a simple pop up window
How to develop in a virtual environment of Python [Memo]
How to build a python2.7 series development environment with Vagrant
Until building a Python development environment using pyenv on Ubuntu 20.04
How to set up a Google Colab environment with Coursera's advanced machine learning courses
How to create a Python 3.6.0 environment by putting pyenv on Amazon Linux and Ubuntu
[Pyenv] Building a python environment with ubuntu 16.04
How to build a LAMP environment using Vagrant and VirtulBox Note
How to access environment variables in Python
How to rebuild python environment from pyenv on Mac environment (El Capitan)
How to build a sphinx translation environment
[Python] How to make a class iterable
How to set up WSL2 on Windows 10 and create a study environment for Linux commands
How to draw a graph using Matplotlib
[Python] How to convert a 2D list to a 1D list
How to set up a simple SMTP server that can be tested locally in Python
I want to set up a GUI development environment with Python or Golang on Mac
[Python] Create a Batch environment using AWS-CDK
I want to build a Python environment
[Python] How to invert a character string
How to install a package using a repository
How to prepare Python development environment [Mac]
How to set xg boost using Optuna
Set up a mail server using Twisted
How to get a stacktrace in python
How to update a Tableau packaged workbook data source using Python
Set up a node to do MNIST on ROS using Tensorflow
How to add python module to anaconda environment
Build a python virtual environment with pyenv
How to set up the development environment of ev3dev [Windows version]
Add a Python virtual environment to VSCode
How to run a Maya Python script
How to generate a new loggroup in CloudWatch using python within Lambda
[Python] What is a formal argument? How to set the initial value
After buying a new Mac, use pyenv + poetry to build a Python environment.
A memo that allows you to change Pineapple's Python environment with pyenv