Let's get started with Python ~ Building an environment on Windows 10 ~

Let's do Python.

I don't think it will hurt to do Python. Since it is a scripting language, it is ** easy to learn ** and ** easy to code **. Interpreter language, ** easy to execute . It is one of the most popular languages ​​ and the community is active. What's more, there are many things you can do ** from web application development to deep learning. I will say it again. ** Python Let's do it. ** **

Environment

** Let's use the virtual environment **. Python uses a lot of libraries, so it's easier to manage if you do it in a virtual environment. here,

  1. Raw Python + pyenv + Poetry
  2. Anaconda

I would like to introduce two of them. The target OS is Windows 10.

Raw Python + pyenv + Poetry

This is the place to make a web application.

Python installation

First, install Python. A interpreter that translates code into machine language. The PythonJapan site is convenient, so let's use it. Visit this site (https://pythonlinks.python.jp/ja/index.html) and download the latest stable installer. As of January 2021, it's the 3.9.1 installer, that is, python-3.9.1-amd64.exe.

python-installer.png

After the download is complete, let's install it. Run the installer. You will enter various initial settings screens, but I think that most of the items are okay without touching them. However, if the checkbox for the item Add Python 3.x to PATH appears, check it. This is so that you can operate Python from PowerShell or a command prompt.

When the installation is complete, close it with Close. Make sure you have installed it successfully. Start PowerShell and

python -V

Execute the command. If the version is displayed, such as 3.9.1, it is OK. python-v_01.png

python-v_02.png

pyenv installation

There are times when you want to change the Python version depending on the project (although I don't have one yet). At such times, you can use pyenv to use multiple versions of Python on the same PC. In short, it's a Python version control tool.

pyenv is a UNIX-like service, so use the Windows version of pyenv-win instead. Run the following command in PowerShell.

pip install pyenv-win --target $HOME\.pyenv

Then run the following command to add the PYENV environment variable.

[System.Environment]::SetEnvironmentVariable('PYENV',$env:USERPROFILE + "\.pyenv\pyenv-win\","User")

Run the following command in PowerShell with administrator privileges.

[System.Environment]::SetEnvironmentVariable('PATH', $HOME + "\.pyenv\pyenv-win\bin;" + $HOME + "\.pyenv\pyenv-win\shims;" + $env:Path,"Machine")

Close PowerShell once and start it again for the settings to take effect.

Now that the installation and initial setup of pyenv is complete, check if it is reflected normally.

In PowerShell, run the following command.

pyenv --version

If the version is output, it's OK.

pyenv --version.png

Manage your current Python with pyenv.

pyenv rehash

pyenv command

--Update of pyenv

pip install --upgrade pyenv-win

--List of supported versions of pyenv

pyenv install -l

--Install any version

pyenv install 3.9.0

--Globalization of any version (to a common version of PC)

pyenv global 3.9.0

--Localization of any version (version within the project)

pyenv local 3.9.0

--Any version of uninstall

pyenv uninstall 3.9.0

Poetry installation

One of the features of Python is that external libraries are important. An external library is simply an extension. It is common to install and use an external library with pip or the like. However, if you install too many libraries, it will be difficult to manage. Therefore, Poetry is a tool that manages libraries for each project.

In PowerShell, run the following command.

(Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py -UseBasicParsing).Content | python

Close PowerShell once to reflect the settings. Start again,

poetry --version

Execute the command.

When the version is displayed, it's OK.

poetry--version.png

As a default setting, execute the following command.

poetry config virtualenvs.in-project true

A virtual environment for virtualenv is now created in your project.

Poetry command

--Poetry update

poetry self update

--Project template generation

poetry new MyProject01
MyProject01
├── pyproject.toml
├── README.rst
├── myproject01
│   └── __init__.py
└── tests
    ├── __init__.py
    └── test_project01.py

--Add library to project (numpy here)

poetry add numpy

MyProject01.png

--Program execution Create main.py in the myproject01 directory.

main.py


  import numpy as np

  x = np.array([1, 2, 3])
  print(x.size)

In the myproject01 directory, run the following command.

  poetry run python main.py

run.png

Anaconda

This is the place to do statistical analysis and machine learning.

Anaconda is a distribution that includes a Pyhon interpreter, an external library often used for scientific calculations, and an IDE that is convenient for development. If you install only Anaconda, the development environment will be ready immediately.

download

First, go to This Site. When you scroll, you will see a screen like this. anaconda.png Click 64-Bit Graphical Installer to download the installer.

Installation

Launch the installer. You will be taken to various initial settings screens, but I think it's okay not to touch most of the items here either. However, if the check box for the item Add Anaconda 3 to the system PATH environment variable appears, check it. This is so that you can operate Python from PowerShell or a command prompt.

After the installation is complete, start Anaconda Powershell Prompt (Anaconda3) from Anaconda3 (64-bit) on the start screen. Then execute the following command.

ipython

ipython.png IPython is the python shell that comes with Anaconda. You can type in the code and execute it. For the time being,

exit()

Let's get out of the shell with.

Editor / IDE

To do programming, you need something called a "text editor" or "integrated development environment" in addition to the one you just installed. These are software for "writing code". The text editor is the minimum function, and the integrated development environment, commonly known as IDE, is multi-functional. There is also a standard Windows version called Notepad, but it is difficult to use, so install it separately.

We recommend PyCharm. It's a Python-only IDE, and it's very good software. There are a paid version and a free version, but basically the free version will suffice. When it comes to framework development, I think the paid version is good.

Install JetBrains Toolbox

PyCharm is developed by a Czech company called JetBrains. JetBrains also develops other useful IDEs such as Intellij IDEA and RubyMine. The software to manage them is JetBrains Toolbox. It is more convenient to use Toolbox than to install it from the official website, so let's use it. Download the installer from this site (https://www.jetbrains.com/ja-jp/toolbox-app/). You can easily install it by running the installer.

Install PyCharm

Launch Toolbox and install`` PyCharm Community.

PyCharm initial settings

It's easy to get a little confused when starting up for the first time, so I will explain it. After starting, click the + mark. Location is the location where you want to save your project. Unless you have a specific reason, create a directory such as Python in the document on drive C or drive D, and create a project in it. Change the Virtualenv below it to raw Python + pyenv + Poetry, or to conda for Anaconda. After that, create a project with CREATE.

Choices other than PyCharm

Also, if you are using Anaconda, IDEs such as JupyterLab and Spyder are included, so you can use that as well. Also, if you are a pervert, please use Vim. Vim best Vim best Vim best Vim best

The environment construction is complete! !! Congratulations! !! !!

Building an environment is the most frustrating part of programming. So failure is a matter of course. If that doesn't work, try the other method or the method introduced on another site.

reference

Using Poetry and pyenv from Python installation on Windows 10 (https://qiita.com/kerobot/items/3f4064d5174676080585)

Thank you for reading until the end!

Recommended Posts

Let's get started with Python ~ Building an environment on Windows 10 ~
Get started with Python! ~ ① Environment construction ~
Getting started with Python 3.8 on Windows
[Python] Building an environment with Anaconda [Mac]
Building a Python 3.6 environment with Windows + PowerShell
Let's get along with Python # 0 (Environment construction)
Building an environment for "Tello_Video" on Windows
[Blender x Python] Let's get started with Blender Python !!
Building a Windows 7 environment for getting started with machine learning with Python
Python hand play (let's get started with AtCoder?)
Building an Anaconda environment for Python with pyenv
Get started with Python on macOS Big Sur
[Definitive Edition] Building an environment for learning "machine learning" using Python on Windows
Build Python environment on Windows
Build python environment on windows
Get started with Python! ~ ② Grammar ~
Building an environment for natural language processing with Python
Procedure for building a CDK environment on Windows (Python)
Create an OpenAI Gym environment with bash on Windows 10
A story about building an IDE environment with WinPython on an old Windows OS.
Building a Python environment on Mac
OpenJTalk on Windows10 (Speak Japanese with Python from environment construction)
Link to get started with python
Anaconda python environment construction on Windows 10
Building a Python environment on Ubuntu
Install python2.7 on windows 32bit environment
Get started with MicroPython (on macOS)
Building a virtual environment with Python 3
How to get started with Python
Building an environment to execute python programs on AWS EC2
Getting started with USD on Windows
Install Python development environment on Windows 10
Get started with Python in Blender
Run the program without building a Python environment! !! (How to get started with Google Colaboratory)
How is the progress? Let's get on with the boom ?? in Python
Example of building python development environment on windows (wsl2, vscode, pipenv)
Get started with the Python framework Django on Mac OS X
Build a 64-bit Python 2.7 environment with TDM-GCC and MinGW-w64 on Windows 7
When I get an error with Pylint in Atom on Windows
Everything from building a Python environment to running it on Windows
[Pyenv] Building a python environment with ubuntu 16.04
Building a Python3 environment with Amazon Linux2
Run servo with Python on ESP32 (Windows)
Python 2.7, 3.4, 3.5 extension module build environment on Windows
Note when creating an environment with python
Creating a python virtual environment on Windows
Build Python environment with Anaconda on Mac
Get Started with TopCoder in Python (2020 Edition)
Create an OpenCV3 + python3 environment on OSX
How Python beginners get started with Python with Progete
Let's develop an investment algorithm with Python 1
Building an environment for "Tello_Video" on Raspbian
Let's install box2d-py with Windows 10 environment pip
A modern environment building procedure for those who want to get started with Python right away
Python on Windows
python windows environment
[Definitive Edition] Building an environment for learning "machine learning" using Python on Mac
Steps to create a Python virtual environment with VS Code on Windows
[Cloud102] # 1 Let's get started with Python (Part 2 Jupyter Notebook Construction AWS Edition)
Get started with Python in 30 minutes! Development environment construction & learn basic grammar
Rock-paper-scissors with Python Let's run on a Windows local server for beginners