Skip to content

Instantly share code, notes, and snippets.

@mrcnc
Last active March 11, 2022 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrcnc/909c3aed4ee5f73eec1cfe680febc71c to your computer and use it in GitHub Desktop.
Save mrcnc/909c3aed4ee5f73eec1cfe680febc71c to your computer and use it in GitHub Desktop.
getting started with conda

getting started with conda

Download Anaconda for a hassle-free way of configuring your development environment.

Download the Python 3 version b/c Python 2 is no longer maintained

If you're wondering "Why not use virutalenv and/or pip?", Anaconda (aka conda) is built specifically for working with the data science ecosystem of languages (Python, R, Julia) and libraries (scipy, numpy, pandas, scikit-learn, plotly/matplotlib), many of which require non-Python build requirements like C/C++ and Fortran compilers.

Use conda to setup a Python 3 environment:

# only need to create the environment once
conda env create -f my-conda-env.yml

# then activate the environment each time you open a new shell
conda activate my-conda-env

Working with the conda environment

Conda makes it easy to manage the data science libraries, which are often difficult to install. Conda can be used as your package manager (instead of pip) and it can install multiple isolated Python versions like virtualenv.

Conda can install dependencies from your existing requirements.txt too with this snippet

while read requirement; do conda install --yes $requirement; done < requirements.txt
# you may also want to add conda-forge as another channel to download from
conda config --append channels conda-forge

But sometimes you may still need to install with pip

After installing or updating dependencies, update the environment file with

conda env export | grep -v "^prefix: " > my-conda-env.yml
@mrcnc
Copy link
Author

mrcnc commented Apr 2, 2020

Other useful conda commands from the docs

List all environments

conda info --envs

remove an environment

conda remove --name myenv --all

create a new python3 env

conda create --name myenv python=3

update to the latest version of a dependency

conda update -n myenv pandas --dry-run

update and environment using a file

conda env update -n myenv --file ~/code/project/myenv-conda-env.yml

@mrcnc
Copy link
Author

mrcnc commented Jan 20, 2021

cat ~/.condarc

ssl_verify: true
channel_priority: strict
channels:
  - conda-forge
  - defaults

@mrcnc
Copy link
Author

mrcnc commented Mar 11, 2022

Conda's systems aren't reliable. I've seen errors like this many times

#16 187.7 CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://conda.anaconda.org/conda-forge/linux-64/libopenblas-0.3.18-pthreads_h8fe5266_0.tar.bz2>
#16 187.7 Elapsed: -
#16 187.7
#16 187.7 An HTTP error occurred when trying to retrieve this URL.
#16 187.7 HTTP errors are often intermittent, and a simple retry will get you on your way.
#16 187.7
#16 187.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment