Python Beginner's Guide (Introduction)

Overview

This is a memo for my review, but I posted it because I thought it might be useful for someone. The reader is intended to be a beginner in Python programming. Python environment construction has a lot of old information, and if you look it up on the net, various information is mixed, so It is the first stumbling block for beginners.

There is a Python environment construction

In building a Python environment

Look at the other articles and briefly conclude the recommended environment construction so as not to get confused. Let's think about the future and build a development environment for Python3 (The introduction method introduced this time can support both python2 and 3) </ Font color>

"pyenv / pip / conda" It is better to build an environment where these three commands can be used! </ Font color>

Beginners are advised to include "anaconda" or "miniconda", which can use the conda command, instead of including official Python. "anaconda" and "miniconda" are a kind of Python distribution, and you can proceed with development with all the main libraries.

Python environment construction

It is old information to build a python environment using virtualenv, easyinstall, setuptools. The ones used for installation are "pyenv (easy to download from installer), pip, conda". For the time being, I will explain what role the introduced ones will play later, so first build the environment.

  1. Install pyenv.

$ curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash $ pyenv update ``` 2. Install python

  • Use pyenv (the one downloaded above)

$ pyenv install --list|grep miniconda #Show the list of installables. miniconda is recommended $ pyenv install xxxxxx #Install version xxxxxx $ pyenv versions #List of installed versions $ pyenv use xxxxxx #Use the specified version $ pyenv version #Check the current version

miniconda/If you installed anaconda, check if the completion works with conda

$ conda update conda #Just in case ``` 3. Install pip

  • Installed by default in Python 3.4 and later versions. Omitted because it is already installed
  • If you have downloaded the 2 series, please click here.
  1. Building a virtual environment
  • conda create -n

  • You can build a virtual environment with pyenv-virtualenv, but we do not recommend it. It is a virtual environment created with conda that can absorb differences between python versions

$ pyenv global miniconda3.XXX  #Define what is called by default among the installed versions $ conda create -n test pandas #Virtual environment construction $ pyenv versions #List of installed versions $ pyenv local miniconda3.XXX/test #If you want to use it as a virtual environment only under this directory $ pyenv global miniconda3.XXX/test #If you want to use the created virtual environment by default ``` The common environment construction part is completed by the above series of work. All you have to do is download the necessary packages as needed, build a new virtual environment as needed when the environment is polluted, and switch.

The role of those who have introduced

Regarding pyenv

A version control tool for python. Get your favorite version of python 2/3 series or anaconda / miniconda, It is possible to switch. How to use here

Regarding pip

A standard python package management tool. Since package installation using conda is more convenient than pip, Beginners may need to be aware of installing packages that are not included in conda with pip. The reason pip is more troublesome than conda is that pip compiles on the client side and can get angry depending on the environment.

Regarding conda

A versatile tool for python's "package management, version control, virtual environment management". If you install anaconda / miniconda, it will come with you without exception. Usually, it is used for building a virtual environment or installing a package as described in the installation method. Version control can also be done with conda, but I download the new version with pyenv and switch between them as I did during installation.

Recommended Posts