Python PyCharm Installation and Usage

PyCharm is a Python integrated development environment (IDE) produced by JetBrains, with intelligent code completion and graphical debugging features, supporting Windows / macOS / Linux all platforms.

PyCharm is an integrated tool for writing code, running programs, debugging, managing projects, and collaborating, and is currently the most mainstream Python development tool in the industry.

In this chapter, we will introduce the installation of Python and PyCharm, and create and run your first Python program.

Stage Content
1. Install Python Download, install, and verify the Python interpreter
2. Install PyCharm Download and install PyCharm Community Edition
3. Create a project Create a new project and create a Python file
4. Write and run code Write hello.py and run it

Installing Python

Python is the interpreter required to run Python programs, and PyCharm relies on it to execute code.

Installing Python consists of three steps: download the installer, run the installation, and verify the installation result.

Download Python

Open a browser and visit the download page on the official Python website:https://www.python.org/downloads/。

The website usually automatically detects your operating system (Windows / macOS / Linux). Click the yellow button on the page to download the latest version.

It is recommended to choose Python 3.10 or above. Currently, mainstream tutorials and third-party libraries have good support for newer versions. Python 2.x was discontinued in 2020, so do not use it anymore.

Install Python

The following takes Windows as an example. macOS and Linux users should refer to the corresponding instructions.

Windows installation steps:

Step Action Description
1 Double-click the installer Run the downloaded .exe file, for examplepython-3.12.x-amd64.exe
2 Check the PATH option

Critical step: At the bottom of the installation interface, checkAdd python.exe to PATH, otherwise the command line may not find Python

3 Click Install Now Just wait for the installation progress bar to complete

macOS users:

You can directly double-click the .pkg installer and follow the prompts to complete the installation, or install via the Homebrew package manager:

brew install python3

Verify Installation

Open a command-line tool (use Command Prompt or PowerShell on Windows, Terminal on macOS), and enter the following command:

python --version

If it displays something likePython 3.12.0a version number, the installation is successful.

On some systems (especially macOS/Linux), the system's built-in python command points to Python 2. In this case, you need to enterpython3 --versionto check the newly installed Python 3.


Installing PyCharm

PyCharm is developed by JetBrains and is one of the most popular Python IDEs.

It has two versions. Beginners can simply choose the free Community Edition:

Edition Cost Target Users Main Features
Professional Paid Professional developers Supports full features such as web development, database tools, scientific computing, etc.
Community Free Beginners / Students Core features for pure Python development, fully sufficient for beginners

Download PyCharm

Visit the PyCharm download page on the JetBrains official website:https://www.jetbrains.com/pycharm/download/。

On the page, findDownloadbutton, and click the download button for the corresponding operating system.

Install PyCharm

The installation methods for different operating systems are as follows:

Operating System Installation Method
Windows Double-click the .exe installer and click "Next" all the way through. It is recommended to check "Create desktop shortcut".
macOS Double-click the .dmg file and drag the PyCharm icon into the Applications folder
Linux You can extract the .tar.gz and runbin/pycharm.sh, or install via Snap

Linux Snap installation command:

sudo snap install pycharm-community --classic

After installation, open PyCharm. On first launch, it will guide you to choose a UI theme and keymap scheme. You can keep the default settings or choose according to your personal preferences.

Install PyCharm

Windows System

  1. Double-click the downloaded installer file (.exe)。
  2. In the installation wizard, choose the installation path; it is recommended to use the default path.
  3. CheckCreate desktop shortcut (Creat Desktop Shortcut)so that you can quickly launch PyCharm.
  4. ClickInstallto start the installation.
  5. After installation is complete, clickFinishto exit the installation wizard.

macOS System

  1. Open the downloaded.dmgfile.
  2. Drag the PyCharm icon into the "Applications" folder.

  3. Find PyCharm in the "Applications" folder and double-click to launch it.

Linux System

  1. Extract the downloaded.tar.gzfile.
    tar -xzf pycharm-*.tar.gz
  2. Enter the extracted directory and findbinfolder.
    cd pycharm-*/bin
  3. Runpycharm.shto launch PyCharm.
    ./pycharm.sh

Configuring PyCharm

When you start PyCharm for the first time, you will be prompted to perform some initial configuration. We can set the language and agree to the terms:

After startup, you can configure personal preferences:

Choose a theme: You can choose the "Darcula" (dark) or "Light" (light) theme.

Configure the Python interpreter: If you have already installed Python, PyCharm will automatically detect and configure the interpreter. If not installed, you can manually add it.

Install plugins: PyCharm will recommend some common plugins, and you can choose to install them as needed.


Creating Your First Project

PyCharm usesProjectas the unit to manage code. A project corresponds to a folder, which can contain multiple Python files.

New Project

After opening PyCharm, click the welcome screen'sNew Project(New Project) button.

In the pop-up creation window, you need to confirm two settings:

Setting Description Example
Location (project location) The save path of the project folder D:\PythonProjects\HelloWorld
Python Interpreter (interpreter) The path of the Python interpreter. PyCharm usually detects it automatically. If not automatically recognized, manually select it.python.exeorpython3

After confirming it is correct, click theCreate(Create) button.

Do not include Chinese characters or spaces in the project path, otherwise some third-party tools may run abnormally. An all-English path is recommended.

New Python File

After the project is created, follow these steps in the PyCharm main window to create a Python file:

Step Operation
1 In the left Project panel, right-click the project root directory
2 SelectNew → Python File
3 Enter a file name (such ashello_example), and press Enter to confirm

PyCharm will automatically generatehello_example.pyfile, and open it in the right editor area for you to write code.


Write and Run Your First Program

After the file is created, write code and run it to see how the Python program executes.

Write Code

Inhello_example.pyEnter the following code in the file:

Example

# File: hello_example.py
# First Python program: greet the user and interact with them

# The print() function is used to output text on the screen
print("Hello, World!")

# The input() function waits for the user to enter content from the keyboard, and the return value is a string
# The text in parentheses is the prompt information displayed to the user
name = input("Please enter your name:")

# f-string (formatted string) can directly embed variables in a string
# The variables in curly braces {} will be replaced with their values
print(f"Hello, {name}! Welcome to learn Python.")

This code does three things:

Code Purpose
print("Hello, EXAMPLE!") Prints a fixed greeting to the screen
input("请输入你的名字:") Displays prompt text on the screen, waits for the user to enter a name, and stores the input in a variable after pressing Entername
print(f"你好,{name}!...") Uses f-string to embed the variablename's value into the greeting to generate personalized output

Run Program

PyCharm provides multiple ways to run; choose any one:

Run method Operation
Context menu Right-click anywhere in the editor area, then selectRun 'hello'
Run button Click the green triangle button in the upper-right corner of the code editor area
Shortcut key On Windows/Linux, pressShift + F10, on macOS pressCtrl + R

After running, PyCharm will pop up at the bottomRun(Run) window, showing the program output:

Hello, EXAMPLE!
请输入你的名字:example
你好,example!欢迎学习 Python。

进程已结束,退出代码为 0

Type your name in the input area of the Run window and press Enter to see the personalized greeting.

If a prompt appears at runtime"No Python interpreter configured", it means PyCharm did not find the Python interpreter. Go toFile → Settings → Project → Python InterpreterManually specify the Python installation path to solve it.


Troubleshooting Common Issues

When using Python and PyCharm for the first time, the following are the four most common problems and their solutions.

Problem symptom Possible cause Solution
Command line inputpythonprompts 'is not recognized as an internal or external command' Add to PATH was not checked during installation Re-run the installer and check this option, or manually add the Python path to the system environment variables
PyCharm prompts that the interpreter cannot be found PyCharm did not automatically detect Python InFile → Settings → Project → Python InterpreterIn ... manually specify the path of the Python executable file
Running code has no response or reports an error Code indentation error or file not saved Check whether the code indentation is consistent (Python strictly requires indentation), and confirm the file is saved (when unsaved, there is a dot mark next to the file name)
Chinese output garbled File encoding is not UTF-8 InFile → Settings → Editor → File EncodingsIn ..., set the encoding to UTF-8
Other Extensions