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.
――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.
--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.
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~
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
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()
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