I tried to touch Python (installation)

Introduction

I have almost never experienced writing a program from scratch as an SE. .. .. This time as well, I received a request to modify the Python program developed by my predecessor. .. ..

I think that there are surprisingly many SEs in the above situation these days. This time I will write down the minimum knowledge required to read Python.

Policy and goals

――This time, I will study at the following site. - https://www.python-izm.com/ --The reference site installs Python directly on your PC. --I want to keep my PC clean, so I use a virtual machine. ――I hope to output something equivalent to "Hello World" as the goal.

Premise

--This time, we will use Vagrant to prepare a Python environment on the virtual machine. --Refer to the previous article (promotion): I tried to win Mac + Vagrant (CentOS7) + Docker + Jenkins --Python version uses 3 series. --Python is not compatible with 2 series and 3 series. --Python2 is pre-installed.

Install Python3

Explicitly install Python 3 series.

Virtual machine


#Check the default Python version of CentOS
##Path confirmation
$ which python
/usr/bin/python
#Python version: 2.7.5
$ /usr/bin/python -V
Python 2.7.5

#Install Python 3 from yum
$ yum -y install python3
~abridgement~
Installed:
  python3.x86_64 0:3.6.8-13.el7

Dependency Installed:
  python3-libs.x86_64 0:3.6.8-13.el7                      python3-pip.noarch 0:9.0.3-7.el7_7                      python3-setuptools.noarch 0:39.2.0-10.el7

Complete!

#Check the version of installed Python 3
##Path confirmation
$ which python3.6
/usr/bin/python3.6
##Python version: 3.6.8
$ python3.6 -V
Python 3.6.8

#Switch Python commands from 2 to 3
##Check the reference of the default Python command: Python2
$ ls -l /usr/bin/python
lrwxrwxrwx. 1 root root 7 Jun  1  2019 /usr/bin/python -> python2
##Save the default symbolic link
$ sudo mv /usr/bin/python /usr/bin/python_bk
##Confirm that there are no more references
$ ls -l /usr/bin/python
ls: cannot access /usr/bin/python: No such file or directory
## Python3.Create 6 symbolic links
$ sudo ln -s python3.6 /usr/bin/python
##Check the reference of the changed Python command: Python3.6
$ ls -l /usr/bin/python
lrwxrwxrwx. 1 root root 9 Sep 25 07:26 /usr/bin/python -> python3.6

#Confirmation after switching Python commands
##Bus confirmation
$ which python
/usr/bin/python
##Python version: 3.6.8
$ python -V
Python 3.6.8

# pip(pkg management system)Commands can also be used
$ pip3 search ansible
ansible-stubs (0.1.dev1)                     - ansible-stubs aids in the development and testing of Ansible roles
~The following is omitted~

Run a Python program (.py)

Now that I have Python3 installed, let's run the program.

Virtual machine


# .Create py file
$ vi test01.py
$ cat test01.py
print('python-izm')

#Created using Python commands.Run py file
$ python test01.py
python-izm

Execute Python interactively

It can also be executed in pairs without preparing a program.

Virtual machine


#Interactive shell launch
$ python
Python 3.6.8 (default, Apr  2 2020, 13:34:55)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.

Interactive shell


# .Run the same as described in the py file
>>> print('python-izm')
python-izm
#Quit to quit()Run
>>> quit()

in conclusion

From installation to program execution, it was as good as any other language. Having an interactive shell seems to be useful when checking the operation, so I have high expectations! Next time, I will study the basic syntax of the source.

Recommended Posts

I tried to touch Python (installation)
I tried to touch Python (basic syntax)
I tried to touch jupyter
I tried to touch the CSV file with Python
I tried to touch Tesla's API
I tried to summarize Python exception handling
I tried to implement PLSA in Python
I tried to implement permutation in Python
I tried to implement PLSA in Python 2
Python3 standard input I tried to summarize
I tried to implement ADALINE in Python
I tried to touch the COTOHA API
I tried to implement PPO in Python
[Python] I tried to calculate TF-IDF steadily
I tried Python> autopep8
I tried to debug.
I tried to paste
I tried Python> decorator
I tried to touch the API of ebay
I tried to get CloudWatch data with Python
I tried to output LLVM IR with Python
I tried to touch Python's GUI library "PySimple GUI"
I tried to implement TOPIC MODEL in Python
I tried to automate sushi making with python
I tried to implement selection sort in python
I tried fp-growth with python
I tried to learn PredNet
I tried to organize SVM.
I tried to implement PCANet
I tried to reintroduce Linux
I tried Python C extension
[Python] I tried using OpenPose
I tried to introduce Pylint
I tried to summarize SparseMatrix
I tried gRPC with Python
I tried scraping with python
I tried to implement StarGAN (1)
I tried to graph the packages installed in Python
When I tried to introduce python3 to atom, I got stuck
I tried to summarize how to use matplotlib of python
I tried to implement Minesweeper on terminal with python
I tried to get started with blender python script_Part 01
I tried to draw a route map with Python
I tried to solve the soma cube with python
I tried to implement a pseudo pachislot in Python
Continuation ・ I tried to make Slackbot after studying Python3
I tried to get started with blender python script_Part 02
I tried to implement Dragon Quest poker in Python
I tried to implement an artificial perceptron with python
I tried to implement GA (genetic algorithm) in Python
[Python] I tried to graph the top 10 eyeshadow rankings
I tried to automatically generate a password with Python3
I tried to summarize how to use pandas in python
I tried to solve the problem with Python Vol.1
I tried to analyze J League data with Python
[Python] I tried to get Json of squid ring 2
I tried to access Google Spread Sheets using Python
I tried to summarize the string operations of Python
I tried to solve AOJ's number theory with Python
I tried to find the entropy of the image with python
I tried to simulate how the infection spreads with Python