Hello everyone. This page is an English translation of a Japanese page. (The original Japanese has been slightly rewritten to make it easier to translate into English.)
I wanted to start learning Python, so I tried to build an environment. The content of this article is a memo of the work I did. The OS of the laptop I am currently using is Windows 10 64bit. This article is an example of how to build the environment for Windows.
Table of Contents
- Install Miniconda and create a virtual environment
- Create a virtual environment with Anaconda Navigator
- Output “Hello World” with PyCharm Community Edition
Install Miniconda and create a virtual environment
I decided to try Python and did some research on the net. It seems that there are various execution environments. I found out that one of them is called Anaconda. It seems to take about 3GB of disk space to install. It seems to be this size because various packages are bundled together.
After further investigation, I found Miniconda, which is the smallest package included in Anaconda. This time, I decided to install this.
You can download the installer for Miniconda from the following site.
I decided to download Python 3.9.
A file named “Miniconda3-py39_4.9.2-Windows-x86_64.exe” was downloaded. We double-clicked on it to start the installation.
During the installation, there is a part where you can choose between the following two users.
- Just Me
- All Users
This time, we chose “All Users”. By default, the top one was selected, but since I don’t use the system to make detailed settings for users, I chose the bottom one.
After completing the installation, the following two items have been added to the Start menu.
- Anaconda Powershell Prompt (Miniconda3)
- Anaconda Prompt (Miniconda3)
As a result of our online research, it seems that the most common way to create a Python virtual environment is to use “Anaconda Prompt”. If you have “Anaconda Navigator” installed, you can use that GUI tool to create a virtual environment. Since “Anaconda Navigator” is not included in Miniconda, we decided to install it.
Create a virtual environment with Anaconda Navigator
Right-click on “Anaconda Prompt” and select “Run as administrator”.
At the above prompt, I typed the following
- conda install anaconda-navigator
Other packages were installed, and “C:\ProgramData\Miniconda3” is now 893 MB.
When I looked at the Start menu, I saw that “Anaconda Navigator” had been added. After checking the version, it showed “anaconda-navigator 1.10.0”. Probably, the latest version was installed.
To create a virtual environment, I started “Anaconda Navigator”.
I clicked on “Environments” in the list on the right, and a list of virtual environments was displayed.
I clicked on the “Create” button at the bottom.
When the dialog box appeared, I entered “test0001” in the [name] field and clicked the [Create] button.
Now we have a new virtual environment called “test0001”.
The following packages have been installed.
# packages in environment at C:\Users\[user name]\.conda\envs\test0001: # # Name Version Build Channel ca-certificates 2021.4.13 haa95532_1 certifi 2020.12.5 py39haa95532_0 openssl 1.1.1k h2bbff1b_0 pip 21.0.1 py39haa95532_0 python 3.9.4 h6244533_0 setuptools 52.0.0 py39haa95532_0 sqlite 3.35.4 h2bbff1b_0 tzdata 2020f h52ac0ba_0 vc 14.2 h21ff451_1 vs2015_runtime 14.27.29016 h5e58377_2 wheel 0.36.2 pyhd3eb1b0_0 wincertstore 0.2 py39h2bbff1b_0
We will not consider the details of the above configuration in this article.
In order to run Python programs in the above virtual environment, we will install the integrated development environment PyCharm Community Edition.
Output “Hello World” with PyCharm Community Edition
We did some research on the Internet and found that PyCharm is a popular integrated development environment. We decided to use the free version this time. The installer can be downloaded from the following site.
A file named “pycharm-community-2021.1.exe” was downloaded. We double-clicked on it to install it.
On the way, we checked the [Create Desktop Shortcut] option. This automatically created a shortcut on my desktop.
A shortcut named “PyCharm Community Edition 2021.1 x64” was created. Double-clicking on it brought up the “Welcom to PyCharm” screen.
We clicked on [New Project].
The [New Project] dialog box is displayed.
The [Location] seems to be the location where the project will be saved. We named the last folder “pythonProject0001”.
For [Python Interpreter] we selected the virtual environment we created above. We did the following (maybe)
- Click on the triangle at the beginning of the string [Python Interpreter].
- Click on the circle at the beginning of the string [Previously configured interpreter].
- Click on the […] to the right of the selection box below it. A dialog box titled [Add Python Interpeter] will appear.
- Click [Conda Enviroment] on the left.
- Click […] on the right side of the [Interpreter] selection box.
- Select C:\Users\[user name]\.conda\envs\test0001\python.exe
The settings are now set to select the virtual environment.
In this state we clicked on the Create button.
The screen now shows the project open.
Right-click [pythonProject0001] on the left side of the screen and click [New]->[Python File] in the list that appears.
In the dialog that appeared, we typed “test0001” and pressed the Enter key.
A new file named test0001.py was created and is now open on the right side.
We typed the following and overwrote and saved the file
We right-clicked on [test0001.py] on the left. In the menu that appeared, we clicked [Run ‘test0001’].
The console of the execution result is displayed at the bottom of the screen, and “Hello World” is output.
This accomplished our goal.
That’s all. I hope this is helpful to you.