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.
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.
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
$ 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" ~
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.
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.
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.
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.
$ 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!
I'm writing such a descriptive article on a blog called Naggi-Tech!