Setting up Anaconda and PyCharm virtual environments: Step-by-step guide
Definition
Anaconda is a package for Python and R languages, providing a convenient conditional free open-source package manager that manages dependencies and distributions.
Since 2020, it has become free only for individual users, universities, non-profit organizations, and small businesses with less than 200 employees. It is now a paid service for government and companies with 200 or more employees.
Reasons to Use Virtual Environments
The reason for using Anaconda is to manage the libraries and versions of Python. By setting up and naming virtual environments, you can easily keep track of the versions and libraries stored in each environment. This makes it convenient to move environments to different locations or reinstall them when needed.
Setting up Anaconda Virtual Environments
Anaconda Installation
Download Anaconda from https://www.anaconda.com/ and install it.
It is recommended to use the default installation path.
If you choose a different installation path, additional configurations may be required based on the IDE you use.
The default path is usually C:\Users\[your computer account name]\anaconda3.
Configuration in PyCharm
When creating a new project in PyCharm, you can create a new virtual environment.
Installing Libraries in PyCharm
Sometimes, the default terminal in PyCharm is PowerShell. In such cases, you need to activate the virtual environment and then install libraries.
To activate the virtual environment:
conda activate (virtual environment name)
Controlling Virtual Environments with Anaconda Console
Opening Anaconda Prompt
Start menu - Anaconda Prompt
Finding Possible Python Versions
conda search python
Creating a Virtual Environment
conda create -n (virtual environment name) python=(desired version)
After that, a list of packages to be installed will be displayed. Type 'y' to proceed with the installation.
Activating the Virtual Environment
If the activation is successful, you will see the virtual environment name instead of (base) in the terminal.
From: (base)current/path>
To: (virtual environment name)current/path>
conda activate (virtual environment name)
Deactivating the Virtual Environment
conda deactivate
Listing Virtual Environments
conda env list
Subscribe to my newsletter
Read articles from Han directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by