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

PyCharm Package Management and Virtual Environments

PyCharm Package Management and Virtual Environments

The strength of the Python ecosystem lies in its rich third-party packages, and managing them and their dependencies is essential for every project.

PyCharm provides a graphical package management interface and an integrated terminal, making installing, upgrading, and uninstalling packages intuitive and efficient.

Meanwhile, PyCharm's support for virtual environments effectively isolates dependency conflicts between different projects.


View and install packages via the graphical interface

PyCharm provides an intuitive package management panel so you can handle daily package tasks without memorizing command lines.

In the right-hand panel, you can see all packages installed under the current interpreter along with their versions.

Type a package name (such as requests) in the search box; once found, click the Install Package button.

After installation, the new package appears in the installed list and is immediately available.

When searching, PyCharm fetches the latest information from the PyPI repository, including the package description, version, and dependencies, to help you choose.


Install packages using the built-in Terminal

If you prefer the command line, PyCharm's built-in Terminal tool window is an excellent choice.

Open the terminal

Click the Terminal tab at the bottom toolbar, or use the shortcut Alt + F12 to open the built-in terminal.

The terminal automatically activates the current project's virtual environment, and the environment name appears before the prompt.

Common pip commands



# Install a single package

pip install requests



# Install a specific version of the package

pip install requests==2.28.0



# Install multiple packages

pip install requests flask numpy



# Upgrade installed packages to the latest version

pip install --upgrade requests



# 卸载包

pip uninstall requests



# List all installed packages

pip list



# View detailed information about a package

pip show requests

PyCharm's built-in terminal is identical to an external one, supporting all pip and system commands and integrating seamlessly with the virtual environment.


Manage virtual environments

A virtual environment is a core practice in Python development; it ensures each project has its own dependency space without interference.

Create a new virtual environment

When creating a new project, PyCharm prompts you by default to create a new virtual environment.

You can also create one manually in an existing project:

  1. Open Settings.
  2. View the existing virtual environments.
  3. Select Add Interpreter and specify the environment location and the base Python interpreter.
  4. Click OK to finish creating it.

Switch to a Conda environment

If you use Anaconda or Miniconda to manage Python environments, PyCharm also offers native support.

  1. On the Python Interpreter settings page, click the gear icon and choose Add...
  2. On the left, select Conda Environment.
  3. Select Existing environment; PyCharm automatically detects the Conda environments installed on the system.
  4. Select the target environment from the drop-down list and click OK to complete the switch.

After switching virtual environments, PyCharm automatically re-indexes the package list. Please wait for indexing to finish; otherwise code completion and type checking may be inaccurate.


requirements.txt auto-detection

requirements.txt is the most common dependency declaration file in Python projects, and PyCharm offers smart support for it.

Automatic detection and prompts

When you open a project containing a requirements.txt file, if PyCharm detects that some packages are not yet installed, a prominent banner appears at the top of the editor.

The prompt is similar to: "Package requirements 'requests', 'flask' are not satisfied".

Click the Install requirements link in the banner, and PyCharm automatically calls pip to install all missing packages.

Generate requirements.txt automatically

You can also let PyCharm generate the requirements.txt file for you.

Run the following command in the terminal:



# Export all installed packages in the current virtual environment to requirements.txt

pip freeze > requirements.txt

After that, when other developers get the project, they only need to run pip install -r requirements.txt to install all dependencies in one step.

It is recommended to include requirements.txt under Git version control, so team members and the CI/CD pipeline can develop and build on the same dependency environment.