Master Anaconda: Create and Manage Conda Environments Like a Pro
This guide walks you through installing Anaconda, checking and updating conda, creating virtual environments with various options, fixing common package‑collection errors, managing packages via conda and pip, switching pip to a faster mirror, and integrating the environments with PyCharm.
Preface
Hello, I’m a three‑year‑old coder sharing my daily Python journey.
Check conda version
Run the following command to see the installed conda version:
conda --versionUpdate conda to the latest version
If conda has not been updated for a while, run: conda update conda When prompted, type y to proceed.
Supplement from the previous article
Note that the Anaconda installer shown only supports Python 3.7 for creating environments.
Create a virtual environment
Command template:
conda create --name <env_name> [interpreter_version] [package_names]Parameters: <env_name> – name of the environment. [interpreter_version] – Python version, e.g., python=3.7. package_names – space‑separated list of packages to install.
Method 1
Create test1 without specifying a Python version (defaults to the highest available):
conda create --name test1Method 2
Create test2 with Python 3.6.6:
conda create --name test2 python=3.6.6Method 3
Create test3 with Python 3.6.4 and install requests and flask immediately:
conda create --name test3 python=3.6.4 requests flaskFix "Collecting package ... failed" error
Locate the .condarc file in your user folder on the C: drive.
Edit the file and replace its content with the following configuration, then restart the command prompt:
ssl_verify: true
channels:
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64/
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64
show_channel_urls: trueThis switches conda to the Tsinghua mirror for faster and more reliable package downloads.
List all environments
conda env listThe highlighted box shows where the environments are stored, which is useful for PyCharm.
Activate a virtual environment
activate <env_name>After activation, the prompt indicates the current environment.
Deactivate the current environment
deactivateInstall third‑party packages in a virtual environment
Method 1 – conda install
conda install --name <env_name> <package_name>Example: install django into test2:
conda install --name test2 djangoMethod 2 – pip install inside the environment
First activate the environment, then run:
pip install <package_name>Speed up pip installations
Replace the default PyPI source with the Tsinghua mirror:
Enter any virtual environment.
Upgrade pip to the latest version: python -m pip install --user --upgrade pip Set the global index URL:
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/After this, all pip installs use the faster mirror.
Use the virtual environment in PyCharm
Run conda env list to find the environment path, then configure PyCharm to use that interpreter.
Additional knowledge
To see which Python executable is being used, run: where python Outside any environment, it points to the Anaconda Python. Inside an activated environment, it points to the environment’s Python, and the same applies to pip and pip3.
Conclusion
This article, based on Anaconda, demonstrates three ways to create virtual environments, install third‑party libraries, and accelerate pip downloads, helping you manage Python projects efficiently.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Python Crawling & Data Mining
Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
