Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyCharm Project Creation and Management

PyCharm Project Creation and Management

In PyCharm, a Project is the most basic unit of work; it contains source code, configuration, dependencies, and environment settings.

This section details how to create and manage Python projects in PyCharm.


1. Create a new project

1.1 Create from the welcome screen

PyCharm actually provides many shortcuts when it starts:

The screen on first launch is as follows:

Click "New Project" (New Project).

Alternatively, from the menu bar File, click "New Project (New Project)".

Configure project settings:

**Location:** Choose and set the project storage path and name.

**Interpreter:** Project venv (recommended).

venv is a Python module for creating and managing virtual environments. A virtual environment is an isolated space that lets you install and manage Python packages without affecting other Python environments on the system.

venv is part of the standard library in Python 3.3 and above, so no extra tools are needed to use it.

**Project template:**

1.2 Create a project from existing code

If you already have Python code, import it in the following ways:

Welcome screen -> "Open" (Open), select the project directory or File -> Open (File -> Open), select the project folder.

PyCharm automatically detects the Python environment; if none is found, you can configure the interpreter manually.


2. Project management

2.1 Project structure

The default PyCharm project structure is as follows:

my_project/  

├── .idea/          # PyCharm 配置文件(如运行配置、版本控制设置)  

├── venv/           # 虚拟环境(如果使用 Virtualenv)  

├── main.py         # 示例代码(如果勾选了 "创建 main.py")  

└── 其他文件/目录     # 用户创建的代码文件

Note: the .idea/ and venv/ folders usually do not need manual editing; PyCharm manages them automatically.

2.2 Configure the Python interpreter

If the project needs a different Python environment (e.g., switching from Python 3.8 to 3.10):

File -> Settings -> Project -> Python Interpreter (Windows/Linux: Ctrl+Alt+S, macOS: Cmd+,).

Click the gear icon -> Add Interpreter, and choose:

Select the Python version and click "OK".

2.3 Run/Debug configurations

PyCharm lets you set different run modes for different scripts:

-

Script path: select the .py files.

-

Python interpreter: make sure the correct environment is selected.

-

Parameters: you can enter command-line arguments (e.g., --port 8000).


3. Common project operations

3.1 Open multiple projects

PyCharm defaults to single-project mode (only one project open at a time), but you can manage multiple projects as follows:

  1. File -> New -> Project (File -> New -> Project), to create a new project (PyCharm will ask whether to open it in a new window).

  2. or File -> Open (File -> Open), select another project directory.

3.2 Close / reopen a project

3.3 Project dependency management (requirements.txt / pyproject.toml)

PyCharm can automatically detect requirements.txt or pyproject.toml and install dependencies:

Right-click requirements.txt -> "Sync Python Requirements".

Or run in the Terminal:



pip install -r requirements.txt

To export the current environment's dependencies:



pip freeze > requirements.txt


4. Frequently asked questions

Q1: PyCharm cannot recognize Python files?

Q2: How do I delete a project?

PyCharm does not delete project files automatically; you must do it manually:

  1. Close the project (文件 → 关闭项目).

  2. Delete the project folder in a file manager (such as Windows File Explorer).

**Q3: How do I back up / share a project?**