How to Set Up a Conda Environment in PyCharm

Let's Efficiently and Quickly Set Up a Conda Environment

Posted by Byolio on October 3, 2024
🌐 中文 English

This article aims to explain Conda environments and how to obtain them.

Hey, I’m Liao Ruipeng. Today, let’s talk about Conda environments.

First Encounter with Conda

After downloading PyCharm, you often see an interface like this: First Encounter with Conda Environment I believe this is where most people first hear about Conda.

What is Conda?

In simple terms: Conda is a general-purpose package manager and environment manager, originally developed by Anaconda. It can manage not only Python packages but also supports other programming languages (such as R, Julia, etc.). Therefore, Conda’s advantage lies in its ability to manage libraries, tools, and dependencies across languages, freeing developers from being limited to a single programming language. Unlike pip, which focuses on managing Python packages, Conda aims to manage the entire development environment, including programming languages, operating system libraries, and tools. This means it not only manages Python packages and installs corresponding Python dependencies but can also install system-level dependencies and libraries for other languages (such as C++ compilers or C language libraries).

Why Install Conda?

Some might mention Conda’s important role in data analysis and machine learning, which is indeed one reason for its widespread adoption. However, besides this factor, another key advantage of Conda lies in its dependency management and handling of built-in third-party dependency files:

  1. Excellent Dependency Management: Conda’s package management mechanism excels at handling complex dependency relationships. When you install a software package, it automatically resolves and installs all dependencies for that package, ensuring version compatibility across all dependencies. This significantly reduces the risk of “dependency hell” (i.e., conflicts between package dependencies), which is especially important when managing multiple packages and using them in different environments.
  2. Built-in Third-Party Dependency Files: Unlike pip, Conda provides pre-compiled binary packages. This means that many packages that depend on specific system libraries (e.g., packages requiring a C compiler) do not need additional compilation steps; Conda automatically installs these dependency libraries. For some common third-party dependency libraries (such as numpy, scipy, pandas, etc.), Conda offers optimized compiled versions that can be installed directly, greatly reducing the hassle for developers to manually compile and configure environments.
    (Because Conda includes a large number of built-in Python third-party dependency libraries, it can meet the needs of most users. Unlike pip, which often requires “magic” methods to install these dependency libraries, Conda solves the frustration for those who cannot use such methods. This is also a reason I recommend it.)

How to Install Conda

After all this talk, it’s time to get to the main event. Let’s see how to install Conda.

  1. Download the Anaconda Installer First, we need to download the Conda installer. You can download it from the Anaconda official website (this link directly points to the download area). condaDownload From there, select the appropriate installer for your operating system to download the Anaconda installer. Since I use Windows, I choose the leftmost option.
  2. Install Anaconda After downloading the installer, we need to install Anaconda. The installation process is very simple; just follow the prompts. anacondaInstall
  3. Configure Conda Environment Variables in PyCharm First, go to the Settings interface in PyCharm and click the Python Interpreter option under Project. (There are many ways to get there; here, I’ll only explain one.) pycharmSetting Click Add Interpreter, select the Conda Environment option, and then click the folder icon button. pycharmConda Find the path where you installed Anaconda, import conda.exe, and finally click the Load Environments button. For example, my path is here: pycharmCondaPath
    After clicking Create New Environment, enter the environment name and its Python version, then click OK to create a new Conda environment.

Summary

Conda is an excellent cross-platform package manager and environment manager that helps developers easily manage Python packages, operating system libraries, and the entire development environment. If you haven’t installed Conda yet, now is the best time to do so.