CodeGym /Courses /Python SELF EN /First Project

First Project

Python SELF EN
Level 3 , Lesson 2
Available

8.1 Exploring the IDE

So, we've created a new project. Let's figure out what's going on here.

1. Project folders and files tree:

This displays the contents of our project's folder - pythonProject.

2. Current open file:

This is just the contents of the file main.py, syntax highlighted.

3. Top menu:

Useful buttons on the top right:

  • "Green triangle" - run project button.
  • "Bug" - start debug mode button.
  • "Magnifier" - project search.
  • "Gear" - settings.

4. Sidebar on the left:

There are a few useful buttons there, one of particular interest is the Terminal button.

5. Status bar:

On the left of the status bar is the path to the current open file. On the right is its encoding: CRLF, UTF-8.

And all the way to the right is the current version of Python - Python 3.12.x which will run our project. It's useful to check this out if you've got several different Python versions installed on your system, and have projects that run on other versions.

8.2 Project breakdown

A standard project consists of files that are displayed in the left panel. These files can be conditionally divided into 4 parts.

Python code files. These files have the .py extension and PyCharm marks them with a blue and yellow icon. Currently, there is only one such file in our project — main.py

Static files. This is what files containing data but not code are called. These can be text files, images, media files, and so on. Currently, there are none in our project.

Python virtual environment. The folder named .venv (short for Virtual Environment) contains Python files as well as several service utilities. The pip package manager will also download third-party libraries you want to use here.

Third-party libraries (External libraries). There are none in our project right now, but when you download them, PyCharm will definitely display them here.

8.3 Virtual environment .venv

Let\'s talk a bit more about the virtual environment. .venv is a module in Python that provides the ability to create different lightweight and isolated virtual environments for Python projects. It is a tool that allows managing project dependencies by isolating them from system libraries. Imagine that this is an isolated room for your project where it can keep its personal toys and tools without disturbing other house residents.

Technically, it works simply: a copy of the Python interpreter and a separate place for libraries are created inside the project folder. This guarantees that if you install a specific version of a library for one project, it will not break another one that needs an older version. Using a virtual environment is a good practice that saves you from endless version conflicts.

Environment management in PyCharm

PyCharm usually takes care of this itself and creates everything automatically. But it happens that you accidentally deleted the necessary folder or just want to start from scratch. Knowing how to manage these settings manually is a useful skill.

Creating an environment

The Python connection status is displayed in the lower right corner. If you see an inscription like Python 3.XX there, it means the installation was successful. The IDE sees the interpreter and is ready to execute your commands.

If it says No interpreter there, click on this text.

  1. In the menu that appears, select Add New Interpreter and then Add Local Interpreter.
  2. In the settings on the left, select Environment. In the center, make sure the checkbox on Generate New is checked.
  3. Click OK. The editor will create a new .venv folder and immediately switch the project to it. Now you have an absolutely clean system without unnecessary junk.

Deleting old or unnecessary ones

Sometimes experiments reach a dead end, and it is easier to delete the environment than to try to fix it. Here is how to do it:

  1. Click on the Python version in the lower right corner again and select Interpreter Settings.
  2. Look for the Python Interpreter field at the top. Expand the list and select Show All.
  3. You will see a list of all environments PyCharm knows about. Select the one you want to remove and click the button with the minus sign in the menu above the list.
  4. An important point: PyCharm will simply "forget" about this environment and stop using it. To physically free up disk space, you need to go to the project folder via a standard file explorer and delete the .venv folder manually.

Creating a second environment

Error: "Already contains Python"

If you go to the add interpreter menu and select Generate new, PyCharm may show a red warning and block the OK button. This happens because the editor habitually tries to create a new environment in the same .venv folder that is already occupied by your first environment. Two different sets of libraries cannot live in the same folder.

How to fix this

You just need to give the new "sandbox" a unique name. Here is how to do it:

  1. Open the Add Local Interpreter menu, as we did before.
  2. Select Generate new.
  3. Look at the Location field. Most likely, the path there ends with the standard name \.venv.
  4. Place the cursor at the end of the line and simply add any digit there. Change the end of the path to \.venv_2 and press Enter.
  5. The red text will disappear immediately. Click OK.

Now two different folders with settings will physically exist in your project, and PyCharm will automatically switch to the new version.

How to switch between environments

The ability to juggle environments is an important skill. But there is a catch here: PyCharm does not always remember your old environments automatically.

It often happens that you created a second environment, and the first one disappeared from the menu, even though the .venv folder is still in the project. In this case, you just need to tell PyCharm where to look for the old Python. Example for switching from .venv_2 to .venv:

  1. Click on the Python version in the corner and select Add New Interpreter -> Add Local Interpreter.
  2. In the window that appears, switch the dot to Select Existing.
  3. In the Python Path field, click on the folder icon on the right.
  4. Now you need to find the Python launch file in your old folder (.venv). Follow the path: Your_project -> .venv -> Scripts (for Windows) or bin (for macOS/Linux).
  5. Inside this folder, select the python file and click OK.

Now the old environment will appear in the settings again and become active. This method works flawlessly, even if PyCharm has "forgotten" about your settings.

8.4 Working with the Terminal

In PyCharm, you can work directly with the command line of your OS. In Linux and MacOS, the command line is called Terminal, so in PyCharm they call it the same. It's not just a whim of PyCharm, but a standard name among programmers.

To open the Terminal you need to click on the terminal button in the side menu:

You should see a window like this:

In this window, you can write commands for your operating system. We're interested in one of them.

Let's find out the current version of the Python interpreter we've installed. To do this, you need to type:


        python --version

Here's what I got:

If you also got Python 3.12.x, then we're on the right track.

Comments (1)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
kim jisoo Level 4, karachi, Pakistan
10 March 2026
UMMMMMM.its kinda hard to understand🧐 🤨