This is the third time I've installed Python, but every time I forget the basics (!), I'll leave it as a reminder.
If you write small details, it will be more difficult to understand, so the content is simply the framework.
**
[1. Python installation](# 1-python installation)
[2. Confirmation of version](# 2-Confirmation of version)
[3. Run a simple program](# 3-Run a simple program)
[4. Install / Uninstall Package](# 4-Install / Uninstall Package)
1. Install Python
The installation method is "Install Python for Windows" on the site ** Python Japan **. /windows/install.html) ”.
I'm sorry I just introduced other sites.
However, if you know a reliable site, you can always install it without hesitation.
2. Check the version
Let's check the Python version as well as confirm that it is installed.
You can check the version with the command python --version
as follows:
command prompt
>python --version
Python 3.9.0
You can also check with the command python -V
as follows (V in -V
is uppercase).
command prompt
>python -V
Python 3.9.0
3. Run a simple program
Here, as a basic method, I will describe how to execute using only the Notepad
and Command Prompt
that are included in Windows from the beginning.
The folder to save the program can be anywhere, but here, create a folder called PythonTest
directly under the C drive.
At my fingertips, the folder directory looks like this:
C:\PythonTest
3-1. Creating a program
In Notepad (any text editor), write the following code and save it as test.py
.
The file name is arbitrary, but the extension must be .py
.
test.py
print("Hello World!")
In my hand, Notepad looks like this:
Needless to say, this code uses the print function to print the characters.
The syntax is print (value to print)
.
3-2. Program execution
Here, the program is executed from the command prompt.
First, you need to change the directory to the folder that contains the file containing the program (test.py
).
To change the directory, execute the command with the pretext of cd [path of the directory to be changed]
as follows.
Note that cd
means "change directory".
command prompt
>cd C:\PythonTest
After moving to the directory where you saved the program files, execute the program by typing the command in the form of python [file name to be executed]
as follows.
command prompt
>python test.py
Hello World!
As mentioned above, if the string Hello World!
Is displayed on the command prompt, it is successful.
4. Install / uninstall packages
Finally, there is a way to install / uninstall packages (libraries) using a package management system called ** pip **.
In addition, pip
is an abbreviation of" ** Pip javax Packages ** "(it is not" Python OSPF Packages "...).
4-1. Package installation
The syntax of the command to install is py -m pip install [package name]
.
When executed, it will be as follows, and finally Successfully installed ・ ・ ・
will be displayed (here, the package that operates the browser called "selenium" is installed).
command prompt
>py -m pip install selenium
Collecting selenium
Downloading selenium-3.141.0-py2.py3-none-any.whl (904 kB)
|████████████████████████████████| 904 kB 1.1 MB/s
Collecting urllib3
Downloading urllib3-1.25.11-py2.py3-none-any.whl (127 kB)
|████████████████████████████████| 127 kB 939 kB/s
Installing collected packages: urllib3, selenium
Successfully installed selenium-3.141.0 urllib3-1.25.11
On mac you can run it with pip install [package name]
, but on Windows you need to put py -m
first (for more information, see" Installing the Python Library-How to Use pip "(https: /) /gammasoft.jp/python/python-library-install/) ".).
At the end, you may see an alert saying "old version" such as WARNING: You are using pip version 20.2.3; however, version 20.2.4 is available.
However, there is no problem in operation.
4-2. Confirmation of installed packages
To see the list of installed packages, type the command py -m pip list
.
You can see that the package selenium 3.141.0
has been added as shown below.
>py -m pip list
Package Version
---------- -------
et-xmlfile 1.0.1
jdcal 1.4.1
pip 20.2.3
selenium 3.141.0
setuptools 49.2.1
urllib3 1.25.11
4-3. Uninstalling the package
The syntax of the command when uninstalling is py -m pip uninstall [package name]
.
On the way, you will be asked if you want to continue the execution with Proceed (y / n)?
. If you don't mind, enter y
to uninstall.
Finally, when Successfully uninstalled ...
is displayed, the process is complete.
command prompt
>py -m pip uninstall selenium
Found existing installation: selenium 3.141.0
Uninstalling selenium-3.141.0:
Would remove:
c:\users\takayama\appdata\local\programs\python\python39\lib\site-packages\selenium-3.141.0.dist-info\*
c:\users\takayama\appdata\local\programs\python\python39\lib\site-packages\selenium\*
Proceed (y/n)? y
Successfully uninstalled selenium-3.141.0
in conclusion
It seems that I will need to handle Python to supplement the VBA program, so I started to touch it for the first time in half a year.
It's so common that you may not have much need for it, but I'll leave a reminder for myself.