Welcome to the exciting journey of learning and growing together as Python developers! Here’s a guide to some essential topics that will help us navigate through our development tasks seamlessly using conda environments. We encourage you to Read and try while learning from this document.
module load anaconda/2023.7
conda
?Conda is a powerful package and environment management system widely used in data science and software development. It simplifies the process of installing, managing, and updating libraries, ensuring consistent and reproducible environments for projects. Conda’s flexibility and ease of use make it a valuable tool for streamlining the development workflow and enhancing collaboration among team members.
A Conda environment is a self-contained workspace where you can manage and isolate dependencies for specific projects, ensuring consistency and reproducibility across different computing environments. It allows users to create encapsulated environments with their own set of packages and configurations, minimizing conflicts and simplifying the management of project-specific requirements.
.condarc
file?The .condarc
file is a configuration file used by Conda to customize its behavior.
It allows us to define preferences for package installations, manage channel priorities, and configure various aspects of Conda’s functionality, providing a tailored environment for efficient development and collaboration.
The .condarc
is written in YML format, but don’t worry about that right now, keep reading and if you want to learn YAML basics you can start here.
.condarc
location?In our team, it is most likely that it is located in your $HOME
You can easily locate the .condarc
file by running the following command:
conda config --show-sources
Additionally, if you wish to set a custom location for the .condarc
file, you can do so by defining the CONDARC
environment variable:
export CONDARC=/path/to/your/custom/location/.condarc
.condarc
Two options
conda config
as seen below.condarc
ConfigurationHere’s an example .condarc
configuration:
# our basic .condarc Configuration File
# Define proxy servers for Conda package downloads
proxy_servers:
http: http://proxy.cslab.openu.ac.il:80
https: http://proxy.cslab.openu.ac.il:80
# Disable SSL verification for package downloads
# (Note: Use cautiously in secure environments)
ssl_verify: False
# Specify the directory for storing Conda packages
pkgs_dirs:
- ~/.conda/pkgs
# Specify the directory for storing Conda environments
envs_dirs:
- $HOME/conda/envs
A “channel” refers to a repository or collection of packages.
Conda channels are used to distribute and access packages for installation.
We can specify additional channels to search for packages using --channel
or by changing .condarc
Common conda channels include:
Make your interaction with Conda smooth and efficient with these commands.
Getting Help:
conda --help
conda env create --help
We can also conda config
command to edit our .condarc
file
For example, changing prompt after activation:
To display only the environment name and not the path after activating, use the following command:
Take a look at your .condarc
file before and after
conda config --set changeps1 False
Here are some options that provide flexibility in tailoring environments to a project needs.
conda env create --name myenv python=3.10 # --> Specify Python Version
conda env create --name myenv numpy pandas # --> Install Specific Packages:
conda env create --name myenv --file another_env.yml # --> Create from Environment File for clonning
conda create --name newenv --clone existingenv # --> Clone an Existing Environment
Conda Versions 4.4 and Later - use conda activate
.
Example: conda activate myenv
Conda Versions Before 4.4 - Use source activate.
Example: source activate myenv
Installing Conda packages is a breeze. Just use the following command:
source activate myenv
conda install <package-name> #
source list
conda install
conda install packageName
conda install packageName=1.2.3 # --> Install a Specific Version of a Package
conda install packageName1 packageName2 # --> Install Multiple Packages
conda install -c channelName packageName # --> Install Packages from a Specific Channel
Most likely you do not need this on our team.
Please! don’t run it unless you understand what your are doing.
Conda init is a command that facilitates the initialization of Conda for seamless integration with your shell environment. By running ‘conda init’, you enable Conda to set up the necessary configurations within your chosen shell (e.g., bash, zsh) so that Conda commands can be conveniently accessed and utilized directly from the command line. This initialization process enhances the user experience by ensuring a smooth and integrated workflow when working with Conda-managed environments and packages.
conda init --dry-run # Display what would have been done.
conda init <shell-name> # Initialize Conda for shell interaction.
conda init --all # Initialize all currently available shells.
conda init --reverse # Undo the effects of the last conda init.
conda env export > environment.yml
conda env create --name <env-name>
conda env create --name <env-name> --file environment.yaml
Copying directories directly is not advised, but if necessary:
conda info --envs
cp -r path/of/original/env location/of/new/env
If you want to clone the environment for self-use (and not for another member of the team):
conda create --name cloned_env --clone original_env
.condarc
possible?Yes, indeed! but most likely you don’t need that in our team.
For a centralized configuration, follow these steps:
4.1.1. Create a Base Configuration File, base_condarc.yml
:
channels:
- defaults
4.1.2. Create Environment-Specific Configuration Files, e.g., development_condarc.yml
and production_condarc.yml
:
# development_condarc.yaml
!include base_condarc.yaml
channels:
- conda-forge
# production_condarc.yaml
!include base_condarc.yaml
channels:
- my-internal-channel
4.1.3. Choose your configuration:
conda config --file development_condarc.yaml
conda config --file production_condarc.yaml
The !include
directive relies on the YAML processor used by Conda,
so please check the Conda documentation for the latest updates.