Introduction of Python

Introduction date

2017-04-22

Latest version of introduction date

Since Python2 is installed by default on the MAC, This time I introduced Python3.

■ Python3 version: 3.6.0 ■ Anaconda3 version: 4.3.1

Introduced on MAC OS

OS X version

■ OS X Yosemite 10.10.5

Homebrew installation

[wikipedia](https://ja.wikipedia.org/wiki/Homebrew_%28%E3%83%91%E3%83%83%E3%82%B1%E3%83%BC%E3%82%B8% According to E7% AE% A1% E7% 90% 86% E3% 82% B7% E3% 82% B9% E3% 83% 86% E3% 83% A0% 29) Deploying software on the Mac OS X operating system It seems to be one of the package management systems that simplifies.

bash


$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

pip installation

It's a Python package management system, like Gem in Ruby. According to the Reference URL It seems that pip is installed by default from Python 2.7.9 or later and Python 3.4 or later. Before I knew this story, I struggled to introduce it with the following command.

■ Install pip

bash


$ curl -kL https://bootstrap.pypa.io/get-pip.py | sudo python

■ pip's own update command

bash


$ pip install -U pip

Install pyenv

pyenv manages the python environment and It seems that you can create a python environment that is different from the standard environment.

(1) Install with homebrew

bash


$ brew install pyenv
$ brew install pyenv-virtualenv

(2) Add settings to .bash_profile (.bashrc)

bash


$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile

(3) Reread

bash


$ source .bash_profile

Installation of Anaconda

■ Check the installable version of Anaconda

bash


$ pyenv install -l

■ Anaconda installation Anaconda is provided by Continuum Analytics and is often used for science and technology, mathematics, engineering, data analysis, etc. in addition to Python itself. This is a package that allows you to install Python packages (400 or more as of February 2016) in a batch. It is widely used by Python developers because it allows for efficient and tedious setup tasks. Anaconda can also be used for commercial purposes. It seems that it is.

・ For Python3 series

bash


$ pyenv install anaconda3-X.X.X

・ For Python2 series

bash


$ pyenv install anaconda2-X.X.X

Summary of how to use pyenv

■ Check the list of installable versions

bash


$ pyenv install -l

■ Installation of Python alone

bash


$ pyenv install 3.6.0

■ pyenv Check the current version

bash


$ pyenv version

■ Check the list of installed versions

bash


$ pyenv versions

■ Setting the version to be used as a whole

bash


$ pyenv global 3.X.X

■ Setting the version to be used only under a specific directory

bash


$ cd PROJECT_DIR
$ pyenv local 3.X.XX
$ pyenv version
Python 2.7.11
$ cd ..
$ pyenv version
Python 3.5.1

Build a virtual environment with conda and switch the environment with activate

(1) Switch the Anaconda environment to global

bash


$ pyenv global anaconda3-4.3.1

(2) Create a virtual environment with conda

bash


$ conda create --name py3.6.0 python=3.6.0

(3) Move to the working folder and execute pyenv local

bash


$ cd [Working folder]
$ pyenv local anaconda3-4.3.1/envs/py3.6.0

(4) Return global to system for the time being (optional)

bash


$ pyenv global system

(5) Activate and switch the environment

$ source $PYENV_ROOT/versions/anaconda3-4.3.1/bin/activate py3.6.0

(6) Check the version of python and Anaconda

bash


$ python -V
Python 3.6.0 :: Anaconda 4.3.1 (x86_64)

(7) Deactivate the environment with deactivate

bash


$ source $PYENV_ROOT/versions/anaconda3-4.3.1/bin/deactivate py3.6.0

(8) To switch the environment again, enter the working folder and activate.

bash


$ cd [Working folder]
$ source $PYENV_ROOT/versions/anaconda3-4.3.1/bin/activate py3.6.0

Recommended Posts

Introduction of Python
Introduction of Python
Introduction of activities applying Python
Introduction of scikit-optimize
Introduction of PyGMT
Basics of Python ①
Basics of python ①
Copy of python
Introduction of python drawing package pygal
Record of Python introduction for newcomers
Introduction of cymel
General Theory of Relativity in Python: Introduction
Easy introduction of speech recognition with Python
Easy introduction of python3 series and OpenCV3
[Introduction to Data Scientists] Basics of Python ♬
[Python] Operation of enumerate
List of python modules
Introduction of trac (Windows + trac 1.0.10)
Copy of python preferences
Basics of Python scraping basics
Introduction of ferenOS 1 (installation)
[python] behavior of argmax
Usage of Python locals ()
Introduction of Virtualenv wrapper
the zen of Python
Introduction to Python language
Introduction to OpenCV (python)-(2)
Installation of Python 3.3 rc1
Python Basic Course (Introduction)
# 4 [python] Basics of functions
Sober trivia of python3
Summary of Python arguments
Python Beginner's Guide (Introduction)
Basics of python: Output
Installation of matplotlib (Python 3.3.2)
Application of Python 3 vars
Various processing of Python
[Introduction to Udemy Python 3 + Application] 26. Copy of dictionary
[Introduction to Udemy Python 3 + Application] 19. Copy of list
Python & Machine Learning Study Memo ②: Introduction of Library
Introduction of Python Imaging Library (PIL) using HomeBrew
Kyoto University Python Lecture Material: Introduction of Columns
[Introduction to Python] Basic usage of lambda expressions
[Python] Correct usage of map
Towards the retirement of Python2
Operate mongoDB from python in ubuntu environment ① Introduction of mongoDB
Summary of python file operations
Summary of Python3 list operations
Python --Quick start of logging
Python
[Introduction to cx_Oracle] Overview of cx_Oracle
Introduction
[python] Value of function object (?)
Automatic update of Python module
Python --Check type of values
[Python] Etymology of python function names
About the ease of Python
Static analysis of Python programs
About various encodings of Python 3
Equivalence of objects in Python
Introduction to serial communication [Python]