DEV Community

An Vo
An Vo

Posted on • Edited on

Conda Environment Setup Guide for MacOS and Pycharm

Conda Environment Setup Guide

This guide helps you set up and use a Conda environment named myenv3.12 with Python 3.12.


1. Install Miniconda

Download the Miniconda installer for your platform from:

https://docs.conda.io/en/latest/miniconda.html

Install via Terminal (macOS, Apple Silicon example):

curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh
bash Miniconda3-latest-MacOSX-arm64.sh
Enter fullscreen mode Exit fullscreen mode

Follow the prompts and restart your terminal after installation.

source ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

2. Create a New Environment

Create an environment named myenv3.12 with Python 3.12:

conda create -n myenv3.12 python=3.12
Enter fullscreen mode Exit fullscreen mode

3. Activate the Environment

conda activate myenv3.12
Enter fullscreen mode Exit fullscreen mode

4. Install Packages

Example: Install numpy and pandas

conda install numpy pandas
Enter fullscreen mode Exit fullscreen mode

5. List Your Environments

conda env list
Enter fullscreen mode Exit fullscreen mode

6. Deactivate the Environment

conda deactivate
Enter fullscreen mode Exit fullscreen mode

7. Remove the Environment (if needed)

conda env remove -n myenv3.12
Enter fullscreen mode Exit fullscreen mode

8. Useful Tips

  • Always activate your environment before working on your project.
  • Install packages only after activating the desired environment.
  • To update conda itself:
  conda update conda
Enter fullscreen mode Exit fullscreen mode

9. List out packages in a specific environment

conda activate myenv3.12
conda list
Enter fullscreen mode Exit fullscreen mode

10. Using Conda Environment in PyCharm

  1. In PyCharm, go to Preferences > Project > Python Interpreter.
  2. Click Add Interpreter > Conda Environment > Existing environment.
  3. Browse to: ~/miniconda3/envs/myenv3.12/bin/python
  4. Click OK to set it as your project interpreter.

11. Create or Update the current environment with an environment.yml file

name: myenv3.12
dependencies:
  - python=3.12
  - pandas
  - numpy
  - matplotlib
  - seaborn
  - scikit-learn
  - tensorflow
Enter fullscreen mode Exit fullscreen mode
conda env create -f backend/environment.yml
Enter fullscreen mode Exit fullscreen mode
conda env update --file environment.yml --prune
Enter fullscreen mode Exit fullscreen mode

Happy coding anvo0000!

Top comments (0)