[Beginner] Installing Python and running programs (Windows)

Introduction

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.

Here, I will touch on four points: install, version check, simple program execution (command input), and package installation / uninstallation. The environment is ** Windows **.

**

** [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: 2020-10-29 201601.png 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.

Recommended Posts

[Beginner] Installing Python and running programs (Windows)
Notes on installing Python3 and using pip on Windows7
[Note] Installing Python 3.6 + α on Windows and RHEL
Install Python and Flask (Windows 10)
The process of installing Atom and getting Python running
Robot running with Arduino and python
Python 3.6 on Windows ... and to Xamarin.
Installing Kivy on Windows10 64bit Python3.5
Integrate Modelica and Python on Windows
Installing Kivy-Designer on Windows10 64bit Python3.5
Sh and py run after installing Python3
Use without installing python 2.x on Windows
Beginner ABC154 (Python)
Beginner ABC156 (Python)
Identify the platform running Python (Kaggle / Colab / Windows)
Install and run Python3.5 + NumPy + SciPy on Windows 10
Python on Windows
(Windows) Causes and workarounds for UnicodeEncodeError on Python 3
python beginner memo (9.1)
Python beginner notes
Try running Google Chrome with Python and Selenium
python windows environment
Install OpenCV 4.0 and Python 3.7 on Windows 10 with Anaconda
Python installation (Windows)
Beginner ABC155 (Python)
[Python] Chapter 02-01 Basics of Python programs (operations and variables)
To avoid seeing hell when installing django-toolbelt on windows, heroku and python3.4 (64bit) ...
[Beginner] Python functions
Beginner ABC157 (Python)
PyQ ~ Python Beginner ~
Trap trapped when running a Python Windows executable
Track Python programs
Installing TensorFlow on Windows Easy for Python beginners
Python beginner memo (2)
Python beginner Zundokokiyoshi
Install ZIP version Python and pip on Windows 10
[Python beginner] Extract prefectures and cities from addresses (3 lines).
[Windows] [Python3] Install python3 and Jupyter Notebook (formerly ipython notebook) on Windows
Installing Python 3 on Mac and checking basic operation Part 1
Create a decent shell and python environment on Windows
[python] Compress and decompress
Python and numpy tips
[Python] pip and wheel
python windows environment construction
Batch design and python
Python iterators and generators
Python installation method Windows
Python packages and modules
Vue-Cli and Python integration
Ruby, Python and map
Python starting with Windows 7
Installing pandas on python2.6
python input and output
Python and Ruby split
python basic on windows ②
Install python on windows
Python3, venv and Ansible
Python asyncio and ContextVar
Install Python (for Windows)
Until you create Python Virtualenv on Windows and launch Jupyter
Python beginner opens and closes interlocking camera with Raspberry Pi