Building a Python environment for programming beginners (Mac OS)

Overview

Python is a very famous and popular programming language.

It is suitable as a language to learn programming for the first time from its easy grammar.

This time, I will build an environment using pyenv and pyenv-vertuakebv on Mac with such a nice detailed explanation of Python, and try a little programming.

You can achieve your goal without reading the explanations of words and phrases, so please proceed in a flexible way according to your own situation.

Premise

It is assumed that Homebrew is already installed.

If you don't have one, please install Hombrew in the article below.

["Homebrew installation" for programming beginners](http://naggi-blog.com/2016/10/programing/%E3%83%97%E3%83%AD%E3%82%B0%E3% 83% A9% E3% 83% 9F% E3% 83% B3% E3% 82% B0% E5% 85% A5% E9% 96% 80% E8% 80% 85% E3% 81% AE% E3% 81% 9F% E3% 82% 81% E3% 81% AE% E3% 80% 8Chomebrew% E3% 80% 8D% E3% 82% A4% E3% 83% B3% E3% 82% B9% E3% 83% 88% E3% 83% BC /)

In addition, please type the command in the article without the front of "$" on your personal computer.

Also, the character after # is a supplement, so it is not a command.

Example

Type the following command in the terminal.

Naggis-MacBook-Air:~ naggigoishi$ ls #Command to see what files are
Applications Documents Dropbox Movies Pictures macports tensorflow
Desktop Downloads Library Music Public node_modules

In the case of the above example, the command I would like you to type in the terminal is

ls

Only. And below that

Applications Documents Dropbox Movies Pictures macports tensorflow
Desktop Downloads Library Music Public node_module

These are the output results.

Installation

Well, let's go for the first time immediately.

In fact, if you have a mac, Python is included in your mac by default.

However, here, we will build an environment for installing the latest version of Python and easily switching versions.

Therefore, I would like to download "pyenv", a package that makes version control easier. (I think python environment is pyenv for short)

Install pyenv

Execute the following commands in order in the terminal.

$ brew update #Update Homebrew
$ brew instal pyenv #Install pyenv

Pass through

$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile #PYENV_Create an environment variable called ROOT
$ echo 'export PATH="$PYENV_ROOT/shims:$PATH"' >> ~/.bash_profile #Added to environment variable called PATH
$ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile #Make shims and autocompletion work.
$ source ~/.bash_profile #bash_Read profile

Now you can use pyenv.

Let's take a look at the version of pyenv to see if it's installed.

$ pyenv --version #「--"version" is an option to check the version. "-v "is also possible
pyenv 1.0.2

In my current case, it was 1.0.2. If it is output like this, it is successful.

The numbers can be different.

I don't think you can tell what's wrong with the comment out on the side, so

Below is a detailed summary of what these are doing.

Introduction to Linux ~ What is "passing through" ~

Python installation

So far, we've made it easy to install your favorite Python.

Now it's time to install Python.

Let's check what can be installed with the following command.

$ pyenv install -list #Show a list of things you can install with pyenv
Available versions:
2.1.3
2.2.3
...
2.7.12
...
3.0.1
...
3.5.2
3.6.0b1
3.6-dev
anaconda-1.4.0
anaconda-1.5.0
...abridgement

Did you get a list like the one above?

The latest version at the time of writing is 2.7.12 for 2 series and 3.5.2 for 3 series.

2 system and 3 system

Even if it is said that it is 2 series or 3 series, I think it is "???".

This is how the version is called.

Those whose version starts with 2 are called 2 series, and those whose version starts with 3 are called 3 series.

Is there such a distinction? That's because Python has been reborn in the 2nd and 3rd series.

There are libraries (extensions / tools) that only work with 2 systems, and vice versa. (At present, there are more 2 systems)

(It's like the PlayStation 3 and PlayStation 4. Some software supports both, and some works only on the PlayStation 3.)

So, if you have a clear idea of what you want to develop and have decided which library to use, check which one the library supports before deciding which one to install.

If you are starting Python from now on, I think the latest 3 series is fine.

Installation

Let's install it.

$pyenv install version to install

When installing 3.5.2.

$ pyenv install 3.5.2

This completes the Python installation.

After that, use the following command to reflect this installation, and you're done.

$ pyenv global 3.5.2 #Version 3 on all local.5.Use 2.
$ pyenv rehash #Reflection of changes

I think you have now reflected the version you specified in your local environment.

Let's actually take a look at the python version.

$ python --version
Python 3.5.2

If it is output as above, it is successful.

Install pyenv-virtualenv

Now you can easily install or change the Python version.

But in the current situation

I can't build a different Python environment with the same version.

For example, suppose you were developing a project with Python version 3.5.2.

In developing the project, we have introduced libraries (extensions, tools) and built a Python environment.

Therefore, when you try to develop a new project with the same version 3.5.2, it cannot be separated from the environment built in the previous project.

Install pyenv-virtualenv to resolve these issues.

Installation

$ brew install pyenv-virtualenv #pyenv-Install vertualenv
$ echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
$ source ~/.bash_profile

Thank you for your hard work. This completes the installation of pyenv-vertualenv! Have a fun code life with python from now on!

Promotion

I'm writing such a descriptive article on a blog called Naggi-Tech!

Recommended Posts

Building a Python environment for programming beginners (Mac OS)
Building a Python environment on Mac
Building a Python development environment for AI development
Building an environment for executing Python scripts (for mac)
Think about building a Python 3 environment in a Mac environment
Python environment construction For Mac
Python3 environment construction (for beginners)
Building a Python virtual environment
Building a Python virtual environment
Write about building a Python environment for writing Qiita Qiita
Building a Docker working environment for R and Python
Building an environment for "Tello_Video" on Mac OS X
Build a machine learning Python environment on Mac OS
Build a Python development environment on Mac OS X
Procedure for building a CDK environment on Windows (Python)
Memo for building a machine learning environment using Python
Error when building mac python environment
Building a Python environment on Ubuntu
Create a Python environment on Mac (2017/4)
Building a virtual environment with Python 3
Python3 TensorFlow for Mac environment construction
Building a python environment for artificial intelligence (Chainer / TensorFlow / CSLAIER)
Building a Python environment on a Mac and using Jupyter lab
[Python] Building a virtual python environment for the pyramid tutorial (summary)
Create a virtual environment for python on mac [Very easy]
[Python] Building an environment for competitive programming with Atom (input () can be used!) [Mac]
[Pyenv] Building a python environment with ubuntu 16.04
[Python] Building an environment with Anaconda [Mac]
Building a Python3 environment with Amazon Linux2
Building a Docker working environment for R and Python 2: Japanese support
Programming environment for beginners made on Windows
How about Anaconda for building a machine learning environment in Python?
Building a Windows 7 environment for getting started with machine learning with Python
Create a python environment on your Mac
Let's create a virtual environment for Python
Creating amateur python environment settings (for MAC)
From building a Python environment for inexperienced people to Hello world
Building a Python 3.6 environment with Windows + PowerShell
Building a conda environment for ROS users
A textbook for beginners made by Python beginners
Building a virtual environment for Mayavi dedicated to Python 3.6, Anaconda, Spyder users
Create a Python development environment locally at the fastest speed (for beginners)
[Definitive Edition] Building an environment for learning "machine learning" using Python on Mac
Introduction to Graph Database Neo4j in Python for Beginners (for Mac OS X)
Selenium + WebDriver (Chrome) + Python | Building environment for scraping
Prepare a programming language environment for data analysis
Building an Anaconda environment for Python with pyenv
Building a Python environment with WLS2 + Anaconda + PyCharm
Build a Python environment on Mac (Mountain Lion)
Building an environment for matplotlib + cartopy on Mac
Build a Python development environment on your Mac
[Python] Web development preparation (building a virtual environment)
Commands for creating a python3 environment with virtualenv
Procedure for creating a Python quarantine environment (venv environment)
Introduction to Programming (Python) TA Tendency for beginners
A memo for creating a python environment by a beginner
Building a Python environment on a Sakura VPS server
python textbook for beginners
Create a Python environment
Mac environment construction Python
OpenCV for Python beginners