Python3 environment construction (for beginners)

1.First of all

1-1. Creation date

2020-01-15

1-1. Latest version of Python3

--As of April 2019, the latest is "Python 3.7.3" --As of November 2019, the latest is "Python 3.8.0" --As of December 2019, the latest is "Python 3.8.1"

1-2. About the environment to build

--The version of Python3 to be installed this time is "Python3.8.1". --Please read as appropriate when the latest version is released. --The development environment uses "Jupyter Notebook".

1-3. Big flow

--Chapter 2: Installing Python3 --Chapter 3: Explanation and construction of virtual environment --Chapter 4: Installing Jupyter Notebook

2. Install Python3

2-1. Windows

2-1-1. Installation

Install Python 3.8.1 on Windows 10 using the official installer.

procedure

  1. Go to Python Official Site (Windows).
  2. Download Stable Releases.
  3. Double-click the downloaded installer-> the installation dialog will appear.
  4. In the middle of the installation dialog, check the "Add Python 3.X to Path" checkbox.
  5. Click "Install Now" to install.

Step 2 Download details

Download Stable Releases. Click "Download Windows x86-64 web-based installer" to start the download. A file (installer) called "python-3.8.1-amd64-webinstall.exe" will be downloaded. キャプチャ1-1.jpg

2-1-2. Confirm that the installation is complete

procedure

  1. Start Command Prompt or Powershell
  2. Check the Python version
  3. Make sure you want to enter Python's interactive mode

Step 1 Details of launching the shell

  1. Press the [Win] + [R] keys-> The "Run" dialog is displayed.
  2. Enter "cmd" and press the "OK" button
  3. Alternatively, type "powershell" and press the "OK" button

Step 2 Details to check Python version

Enter the following command

> python -V

OK if it is output (displayed) as follows

Python 3.8.1

Step 3 Details of confirming whether to enter Python interactive mode

Enter the following command

> py

OK if it is output (displayed) as follows

Python 3.8.1 ...(Information such as date (depending on installed version and environment))
Type "help", "copyright", "credits" or "license" for more information.
>>>

If ">>>" is displayed, it is OK. In this interactive mode, enter a Python3 program and press "Enter" to execute the program. To exit interactive mode, press "quit ()" or "[Ctrl] + [z] + [Enter]".

2-2. macOS

2-2-1. Installation

--Python 2.7 is installed by default --May replace Python 3.X in the near future --This is because macOS uses tools that use Python. --Here, we will install Python 3.X in a way that coexists with Python 2.7. --Install using the official installer on macOS 10.9 and later versions,

procedure

  1. Go to Python Official Site (macOS).
  2. Download Stable Releases.
  3. Double-click the downloaded installer-> the installation dialog will appear.
  4. Follow the instructions to install.
  5. Allow the use of macOS SSL root certificate.

Step 2 Download details

Download Stable Releases. Click "Download macOS 64-bit installer" to start the download. A file (installer) called "python-3.8.1-macosx10.9.pkg" will be downloaded. キャプチャ2.JPG

Step 5 Details of permitting the use of SSL root certificate of macOS

Start the terminal

$ cd /Applications/Python\ 3.8/Install/
$ ./Install\ Certificates.command

2-2-2. Confirm that the installation is completed

procedure

  1. Start the terminal
  2. Check the Python version
  3. Make sure you want to enter Python's interactive mode

Step 2 Details to check Python version

Enter the following command

> python3 -V

OK if it is output (displayed) as follows

Python 3.8.1

Step 3 Details of confirming whether to enter Python interactive mode

Enter the following command

> python3

OK if it is output (displayed) as follows

Python 3.8.1 ...(Information such as date (depending on installed version and environment))
Type "help", "copyright", "credits" or "license" for more information.
>>>

If ">>>" is displayed, it is OK. In this interactive mode, enter a Python3 program and press "Enter" to execute the program. To exit interactive mode, use "quit ()" or "[control] + [d]".

3. Explanation and construction of virtual environment

Description of virtual environment

--You can build multiple Python execution environments on one computer. --It is also possible to run multiple versions of Python and libraries. --Example) If you are developing two Python programs, X and Y, it will be useful if you use different versions of each.

Reference site for virtual environment

Building a virtual environment

Virtual environment

A Python virtual environment is created in units of folders placed in a specific location. For example, if you build a virtual environment in C: \ env_test \` ``, libraries etc. will be placed under the` env_test``` folder.

Delete virtual environment

Delete the virtual environment folder (put it in the trash).

Tips for building a virtual environment

The virtual environment will be built for the number of software to be developed (a lot). Don't lose track of where you built your Python 3 virtual environment The virtual environment of Python3 is here! Create one place (folder), It is recommended to build a virtual environment under it. I,

¥Users¥hoge¥Documents¥dev¥python


 Is set as the development environment (virtual environment) folder of Python3 and operated.

### Building a virtual environment
 Start a command prompt (windows) or powershell (windows) or terminal (macos).

 This time,

#### **`En in \ Users \ hoge \ Documents \ dev \ python_Build a virtual environment named wk.`**
``` c


 First, move to the folder where you want to build the virtual environment.


#### **`Enter the following command (move folder)`**
```language
> cd C:\Users\hoge\Documents\dev\python

on macos
$ cd C:\Users\hoge\Documents\dev\python

Enter the following command (virtual environment construction)

> python -m venv env_wk

on macos
$ python3 -m venv env_wk

Virtual environment enabled

Just building a virtual environment doesn't make much sense. Activate the virtual environment you have built.

Move the folder to the built virtual environment. (Not required if moved)

Enter the following command (move folder)

> cd C:¥Users¥hoge¥Documents¥dev¥python

on macos
$ cd C:\Users\hoge\Documents\dev\python

Enter the following command (enable virtual environment)

> env_wk¥Scripts¥Activate.py
Or
> env_wk¥Scripts¥Activate.bat

on macos
$ env_wk\bin\
$ source ./activate

Once enabled, the virtual environment folder name will be displayed before the prompt `` (env_wk)> `.

When the virtual environment is enabled, it will be displayed as follows

(env_wk) C:¥Users¥hoge¥Documents¥dev¥python>  

Disable virtual environment

To deactivate a virtual environment, run the deactivate command. You can see that the prompt returns to the standard notation and exits the virtual environment.

Enter the following command (disable virtual environment)

(env_wk) > deactivate

4. Install Jupyter Notebook

Installation

Enable the virtual environment and enter the following command.

Enter the following command

(env_wk) > pip install jupyter

If it fails, enter the following command and try again.

Enter the following command

(env_wk) > pip install -U pip

Launch Jupyter Notebook

Enter the following command

(env_wk) > Jupyter Notebook

If the web browser starts and the `Jupyter` screen is displayed, it is successful.

Addition of functions

The standard libraries (functions) used in the fields of machine learning and data analysis are as follows. --Numpy (a function for efficient numerical calculation) --SciPy (Numerical analysis function for mathematics, science, engineering) --pandas (functions that support data analysis) --matplotlib (function for drawing graphs) --scikit-learn (function for machine learning)

Please install (add functions) at once.

Enter the following command

(env_wk) > pip install numpy scipy pandas matplotlib scikit-learn

Other reference articles

If you can afford it, please refer to the following articles. Introduction of Python 3 which is the easiest in the world

Recommended Posts

Python3 environment construction (for beginners)
Python environment construction For Mac
Python environment construction
Environment construction (python)
python environment construction
Python --Environment construction
Python environment construction
python environment construction
Python3 TensorFlow for Mac environment construction
Python project environment construction procedure (for windows)
python windows environment construction
Python development environment construction
python textbook for beginners
python2.7 development environment construction
Mac environment construction Python
OpenCV for Python beginners
Python environment construction @ Win7
Python environment for projects
Python + Anaconda + Pycharm environment construction
Learning flow for Python beginners
Python environment construction (Windows10 + Emacs)
CI environment construction ~ Python edition ~
Anaconda3 python environment construction procedure
Python environment construction and TensorFlow
Python #function 2 for super beginners
Basic Python grammar for beginners
Python environment construction under Windows7 environment
[MEMO] [Development environment construction] Python
100 Pandas knocks for Python beginners
[For organizing] Python development environment
Python for super beginners Python #functions 1
Python #list for super beginners
~ Tips for beginners to Python ③ ~
Environment construction of python2 & 3 (OSX)
Ansible environment construction For Mac
Easy-to-understand explanation of Python Web application (Django) even for beginners (1) [Environment construction]
[Python] Django environment construction (pyenv + pyenv-virtualenv + Anaconda) for macOS
Building a Python environment for programming beginners (Mac OS)
Python environment construction memo on Windows 10
Get started with Python! ~ ① Environment construction ~
Python Exercise for Beginners # 2 [for Statement / While Statement]
Anaconda python environment construction on Windows 10
Python + Unity Reinforcement learning environment construction
Python for super beginners Python # dictionary type 1 for super beginners
I checked Mac Python environment construction
Python #index for super beginners, slices
Python development environment options for May 2020
Python development environment construction on macOS
Python environment construction (pyenv + poetry + pipx)
<For beginners> python library <For machine learning>
Emacs settings for Python development environment
Environment construction of python3.8 on mac
Python #len function for super beginners
Python3 environment construction with pyenv-virtualenv (CentOS 7.3)
Beginners use Python for web scraping (1)
Run unittests in Python (for beginners)
Emacs Python development environment construction memo
pytorch @ python3.8 environment construction with pipenv
Beginners use Python for web scraping (4) ―― 1
Python #Hello World for super beginners
Python for super beginners Python # dictionary type 2 for super beginners