A layman wants to get started with Python

Manuals in the world are so difficult that you can't think they are written in Japanese

First of all, there are too many stories about building a difficult environment in the world.

--Set for each folder --To be able to change for each project --You can save your settings --Create requirement.txt for later!

No, real beginners like us don't need it, so please tell me only the shortest route. It is a story. Personally, I think it's a waste to not be able to start by stumbling on something that is not needed in the current development. All you have to do is set the minimum settings and move as you see fit.

If you build an environment that is properly prepared, some people will get mounts in the future, and some people will point out the right thing, but if you are a beginner and want to get started, this is the way to go! I wrote that. You can get started with Python in as little as 10 minutes.

However, for those who have hit the command prompt and Bash commands a little. Someone who knows about cd, ls and pwd. If you don't want to type a command or a line, give up writing code and rely on a data robot.

Windows, Ubuntu

Download and install Anaconda

Anaconda is very fast. Download and install Anaconda. It's heavy, but you can put it in. Just move. This article is easy to understand.

[Download and install Anaconda](https://qiita.com/t2y/items/2a3eb58103e85d8064b6#windows-%E3%81%A7%E3%81%AE%E3%82%A4%E3%83%B3%E3 % 82% B9% E3% 83% 88% E3% 83% BC% E3% 83% AB% E6% 96% B9% E6% B3% 95)

Create a virtual environment

Once installed, it's easy to use without using the Anaconda GUI at all. As a result, I got used to it. Create a virtual environment at the command prompt (or Anaconda prompt). Why do you need a virtual environment? What? It's written all over the place, so let's google it.

For example, if you want to create a python3.7 system environment, just hit the following. Only env_name should be your favorite name. Personally, I recommend a name like py37_project so that you can see the version.

    conda create -n env_name python=3.7

After that, activate the virtual environment and add the packages you need. The following is an example.

    conda activate env_name
    conda install numpy matplotlib
    conda install scikit-leran

For those who want to know more, the following article is detailed.

[For beginners] Create a virtual environment with Anaconda

Specify the virtual environment in the IDE or Editor

Now I have two choices, VS CODE or PyCharm. Personally, it's one of VSCODE, but I think PyCharm is easier to set up. What is launch.json so delicious for an amateur? I wonder if it's a level. I didn't really understand it in the past. .. I think PyCharm works when you click it for the time being.

Select project interpreter from the settings. [Python development environment memo](https://qiita.com/mm_sys/items/8fae23d569c42453c69b#project%E3%82%92%E4%BD%9C%E3%81%A3%E3%81%9F%E5% BE% 8C% E3% 81% AB% E5% A4% 89% E6% 9B% B4% E3% 81% 99% E3% 82% 8B).

If you include a Python extension, the Interpreter selection will be suggested, and you can change it by pressing the icon at the bottom left. [How to build Python and Jupyter execution environment with VS Code](https://qiita.com/SolKul/items/f078877acd23bb1ea5b5#python%E3%82%A4%E3%83%B3%E3%82%BF%E3% It is written in 83% 97% E3% 83% AA% E3% 82% BF% E3% 82% 92% E8% A8% AD% E5% AE% 9A% E3% 81% 99% E3% 82% 8B) ..

Hello, World

After that, for the time being, create a file called main.py and execute the following to move it.

main.py


    print('Hello, World')

MacOS

Installation of Pyenv and Pyenv Virtualenv

The Mac is extremely incompatible with Anaconda (rumors), so I put Pyenv and Virtualenv quietly. Pipenv may be good for a while! I thought, but in a blink of an eye it wasn't updated and disappeared somewhere (I'm aware) I also used Pipenv a long time ago, and the environment broke before I knew it, and I don't have good memories. I'm sorry for Pipenv followers.

As long as Homebrew is included, it is a single command. See below for more information.

Comfortable python environment with MacOS, Homebrew and pyenv.

    brew install pyenv

Pyenv settings

Don't be afraid to add it to your Shell settings. Well, if you want to run Python on a Mac, you should be able to edit this much. Add these three lines to your .zshrc or .bash_profile.

shell:.zshrc,.bash_profile


    export PYENV_ROOT="$HOME/.pyenv"
    export PATH="$PYENV_ROOT/bin:$PATH"
    eval "$(pyenv init -)"

After completing the settings, restart the shell or execute the following.

    zsh -l
      or
    source ~/.bash_profile

Installing Python with Pyenv

Check the version that can be installed

    pyenv install --list

Install the desired version

    pyenv install 3.7.7
    pyenv install 3.7.6

You can put as many types as you like. Enter the version you want to use.

Install Virtualenv and create a virtual environment

Installation

    brew install pyenv-virtualenv

Creating a virtual environment

Now you can create a virtual environment based on 3.7.7.

    pyenv virtualenv 3.7.7 env_name

After that, you can add modules just like anaconda.

    pyenv activate env_name
    pip install numpy matplotlib
    pip install scikit-leran

You can also link the environment to the folder and do such fashionable and convenient things, so please refer to here.

Create a Python (pyenv / virtualenv) development environment on Mac (Homebrew)

Summary

There are many in-house inquiries asking, "I really want to use Python for the first time." At the very least, I would like people who say that they can only hit commands to create and develop a virtual environment.

I think there are people who think that Anaconda should be installed from the beginning and Jupyter should be launched from the GUI, and that is also the correct answer.

However, in most cases, I think that .py will be created in the end, so I wonder if it's okay to prepare only that from the beginning. Personally, I think it makes sense to launch jupyter after preparing up to this point.

That's it.

Recommended Posts

A layman wants to get started with Python
Link to get started with python
How to get started with Python
[Python] A memo that I tried to get started with asyncio
Get started with Python! ~ ② Grammar ~
I tried to get started with blender python script_Part 01
How to get started with Scrapy
How to get started with Django
Get started with Python in Blender
Minimum knowledge to get started with the Python logging module
Step notes to get started with django
I tried to get started with Hy
How Python beginners get started with Python with Progete
How to get started with laravel (Linux)
[Blender x Python] Let's get started with Blender Python !!
I wrote a script to get you started with AtCoder fast!
Here's a brief summary of how to get started with Django
[Python] How to get a value with a key other than value with Enum
Run the program without building a Python environment! !! (How to get started with Google Colaboratory)
Python hand play (let's get started with AtCoder?)
How to read a CSV file with Python 2/3
Send a message to LINE with Python (LINE Notify)
[Python] Get the files in a folder with Python
The easiest way to get started with Django
A modern environment building procedure for those who want to get started with Python right away
Get a ticket for a theme park with python
Introduction to Tornado (1): Python web framework started with Tornado
[Python] To get started with Python, you must first make sure you can use Python.
Try to draw a life curve with python
I want to make a game with Python
Getting Started with Python
I tried to get CloudWatch data with Python
Decide to assign a laboratory with Python (fiction)
I get a UnicodeDecodeError when trying to connect to oracle with python sqlalchemy
Steps to create a Twitter bot with python
Get started with MicroPython
Get started with Python on macOS Big Sur
Get date with python
Get started with Mezzanine
Getting Started with Python
I want to write to a file with Python
Materials to read when getting started with Python
[Cloud102] # 1 Get Started with Python (Part 1 Python First Steps)
Python script to get note information with REAPER
Get a quick Python development environment with Poetry
For those who want to learn Excel VBA and get started with Python
5 Reasons Processing is Useful for Those Who Want to Get Started with Python
How to get a list of files in the same directory with python
[Introduction to Python] How to get the index of data with a for statement
How to convert / restore a string with [] in python
[First API] Try to get Qiita articles with Python
A memo connected to HiveServer2 of EMR with python
[Python] How to draw a line graph with Matplotlib
Try to make a command standby tool with python
Python Ver. To introduce WebPay with a little code.
Get financial data with python (then a little tinkering)
I tried to draw a route map with Python
How to get a logged-in user with Django's forms.py
Super Primer to python-Getting started with python3.5 in 3 minutes
From buying a computer to running a program with python
[Python] A memo to write CSV vertically with Pandas