Create your first PyCharm project

Environment: Install Python

Since we are creating a Python project, Python must be installed.

Step1: double-click to open PyCharm and click Create New Project:

Step2: choose Pure Python, offer to create the location of the project, I put this project on my computer under the path/User/xuxh PycharmProjects/and give the project name for the demo:

In the left panel, PyCharm lists all the project types supported by PyCharm. In addition to Pure Python, PyCharm also supports the popular Web frameworks Django and Flask, as well as Google App Engine framework. It also supports many of the most widely used front-end Web frameworks, such as Angular, React, and so on. All in all, PyCharm supports a wide variety of projects.

Click the arrow and Pycharm will find the previously installed Python interpreter. Select the interpreter and click the Create button.

Returning to the main page, you see that the initial project structure consists of three parts:

Step3: Right-click the project name and create a New Python File: New -> Python File:

Type the file name “hello_world” and press Enter to create the hello_world.py file.

Step4: Write a simple program that prints “Hello world!!” :

Step5: To Run the program, right click on the editing area and choose Run ‘hello_world'(you can also click the menu Run -> Run ‘hello_world’).

Step6: go to the run console and see that PyCharm has printed “Hello World!!” .

Create and manage projects using PyCharm

Project concept

Whatever is done in PyCharm is done in the context of the project. A project is an organizational unit that represents a complete software solution. The main effect is a project definition, scope constraint, specification type, which is a bit of a mouthful. Now we can simply think of the project as a simple catalog.

The project file

PyCharm automatically generates a.idea folder when you create a new project. The main function of this folder is to store project control information, including version information, history, and so on. The.idea directory is not visible in the Project view. To see the contents of the.idea directory, select the “Project” toolbar, click the arrow on the right, and select Project Files:

Here is the contents of the.idea directory:Let’s take a look at what each of these files does:

  • . Iml file: describes the project structure;
  • Workspace. XML file: contains workspace related parameters and options;
  • XML files: Each XML file is responsible for its own set of Settings, identified by its name: projectCodestyle.xml, encoding.xml, Vc.xml, and so on.

Project type

PyCharm automatically generates a series of project files, libraries, and.idea directories for different project types. In the screen for creating a new project, you can see the following project types supported by PyCharm:

Here are the main types of projects:

  • Pure Python: For Pure Python programming. The directory structure of such a project contains PyCharm specific Settings, project files, libraries, and the.idea directory. Python needs to be installed in advance, and the demo we created last time was a Pure Python project.
  • Django: This project type provides the specific infrastructure for your Django application and all the necessary files and Settings. Using Django applications requires a database, and SQLite is preconfigured in the IDE. If you use another database engine, you need to install and configure it correctly.
  • Flask: This project type provides the specific infrastructure for the Flask application and all the necessary files and Settings.
  • Google App Engine: This project type provides the specific infrastructure for the Google App Engine application, along with all the necessary files and Settings.
  • Client projects: HTML5 Boilerplate, Bootstrap, and Foundation are all client projects. For client applications, PyCharm creates a specific infrastructure with the required files and directories.

Create a project

Creating a new project

On PyCharm’s main screen, click File -> New Project:

Go to the Welocme to PyCharm window and select Create New Project:

Import items from source files

  • inPyCharm Click on the main screen ofFile -> Open;
  • In the dialog that opens, select the directory that contains the source code you want;

  • After selecting the project to open, click in the lower right corner"Open"Button;
  • In the window that pops up, specify whether to open the new project in a separate window or close the current project and open it in the current window.

Manage the project

Project configuration

Project configuration mainly involves configuring the project structure, which defines the entire project package file, and the interpreter, which specifies the Python environment on which the program runs. Correct configuration of the above two items can ensure the normal operation of the program. Detailed configurations are described in the subsequent chapters.

Click On PyCharm -> Preferences;

For Windows and Linux, click File -> Settings;

In addition, you can configure the project Settings not only for the current project, but also for all Projects you will create later: File -> New Projects Settings -> Preferences for New Projects.

Open the project

The project can be opened from the Welocme to PyCharm window, and you can select Open directly. In addition, PyCharm keeps a list of recent project history, which you can open by selecting the project you want from the left-hand list.

You can also Open the project from the main menu File -> Open Recent.

PyCharm allows you to open multiple projects simultaneously. When you open one project and then another, there will be a popup below.

New Window and This Window: Each item opens in its own Window. Projects are independent and cannot share information, except for clipboard operations. All projects run in the same PyCharm instance and use the same memory space. Attach: A newly opened project shares the same window as an already opened one. An open project is considered the main project and always appears first in the Project tool window. All other projects are added to the main project. As shown in the figure:

Close the project

From the main menu File -> Close Project.

PyCharm displays the Welcome screen when there is only one open item and you close it. If more than one project is open, PyCharm will only close the current project. In addition, if you want to separate any items attached to the main project in a window, simply remove the target project from the Project View. “Project” tool window, to delete the Project right-click, select Remove from Project View:

Switching between projects

PyCharm allows you to open multiple projects in different Windows. How to switch between open projects? Use the following command:

Window -> Next Project Window 
Window -> Previous Project Window 
Copy the code

Clear the cache

PyCharm caches a large number of files. When PyCharm runs for a long time, the amount of data is very large and consumes system resources. So at some point we need to clear the cache. For example, a short-term project may end up not being used in the future; The only way to resolve some conflicts is also by clearing the cache. File -> Invalidate Caches/Restart

This article is constantly updated. You can search “Geek night Reading” on wechat to read it for the first time. More Python learning articles are your motivation!