Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #198039 > unrolled thread

Best practise for managing Conda environments?

Started byMartin Schöön <martin.schoon@gmail.com>
First post2026-09-21 09:17 +0000
Last post2026-09-25 08:53 +0000
Articles 1 on this page of 21 — 6 participants

Back to article view | Back to comp.lang.python


Contents

  Best practise for managing Conda environments? Martin Schöön <martin.schoon@gmail.com> - 2026-09-21 09:17 +0000
    Re: Best practise for managing Conda environments? Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-09-21 17:32 +0800
      Re: Best practise for managing Conda environments? Martin Schöön <martin.schoon@gmail.com> - 2026-09-21 20:33 +0000
        Re: Best practise for managing Conda environments? Jon Ribbens <jon+usenet@unequivocal.eu> - 2026-09-21 22:05 +0000
          Re: Best practise for managing Conda environments? Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-09-22 14:37 +0800
            Re: Best practise for managing Conda environments? ram@zedat.fu-berlin.de (Stefan Ram) - 2026-09-22 07:33 +0000
            Re: Best practise for managing Conda environments? Jon Ribbens <jon+usenet@unequivocal.eu> - 2026-09-22 09:08 +0000
              Re: Best practise for managing Conda environments? Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-09-22 22:53 +0800
    Re: Best practise for managing Conda environments? Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-09-22 15:08 +0800
    Re: Best practise for managing Conda environments? Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-09-22 07:44 +0000
      Re: Best practise for managing Conda environments? "Loris Bennett" <loris.bennett@fu-berlin.de> - 2026-09-22 10:14 +0200
    Re: Best practise for managing Conda environments? Martin Schöön <martin.schoon@gmail.com> - 2026-09-22 19:53 +0000
      Re: Best practise for managing Conda environments? Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-09-23 04:57 +0800
        Formatting (was: Best practise for managing Conda environments?) ram@zedat.fu-berlin.de (Stefan Ram) - 2026-09-23 08:17 +0000
          Re: Formatting Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-09-23 20:08 +0800
            Re: Formatting ram@zedat.fu-berlin.de (Stefan Ram) - 2026-09-23 12:42 +0000
              Re: Formatting ram@zedat.fu-berlin.de (Stefan Ram) - 2026-09-23 14:43 +0000
                Re: Formatting ram@zedat.fu-berlin.de (Stefan Ram) - 2026-09-23 15:01 +0000
            Re: Formatting ram@zedat.fu-berlin.de (Stefan Ram) - 2026-09-23 13:38 +0000
          Re: Formatting (was: Best practise for managing Conda environments?) Martin Schöön <martin.schoon@gmail.com> - 2026-09-24 08:31 +0000
            Re: Formatting (was: Best practise for managing Conda environments?) Martin Schöön <martin.schoon@gmail.com> - 2026-09-25 08:53 +0000

Page 2 of 2 — ← Prev page 1 [2]


#198065 — Re: Formatting (was: Best practise for managing Conda environments?)

FromMartin Schöön <martin.schoon@gmail.com>
Date2026-09-25 08:53 +0000
SubjectRe: Formatting (was: Best practise for managing Conda environments?)
Message-ID<nhmr51F9mo6U1@mid.individual.net>
In reply to#198064
Den 2026-09-24 skrev Martin Schöön <martin.schoon@gmail.com>:
><snip>
>
> My problem is the unique 'mark up' I need to weed out...
>
> Also, some questionable tips are hiding among the good ones. I will keep
> them but add comments. I think it illustrates nicely how careful you
> need be when reading LLM produce.
>
OK, let's see how I managed. Org-mode kind of markup used:

* Heading 1
** Heading 2
~code~
+ list bullet
*bold*
/emphasis/

# Python style inline comment by me.

###################################################################

Mistral Small 4 on bets practice for managing virtual environments
using conda.

Managing virtual environments with Conda (Anaconda/Miniconda) is
essential for isolating project dependencies and avoiding
conflicts. Here are the best practices. By following these
practices, you ensure reproducible, conflict-free environments for
your projects.

* Create isolated environments
Always create a dedicated environment for each project to
avoid dependency conflicts.

Create a new environment with a specific Python version:

~conda create --name my_project python=3.9~

Activate the environment:

~conda activate my_project~

*Best Practice:*
+ Use descriptive names (e.g., `my_project_dev', `data_science_env').
+ Specify Python versions explicitly (`python=3.9' instead of just
  `python').

* Export and recreate environments
To share or replicate an environment, export its dependencies to
a YAML file.

Export the environment to a YAML file:

~conda env export --name my_project > environment.yml~

Recreate the environment from the YAML file:

~conda env create --file environment.yml~

*Best Practice:*
+ Commit environment.yml to version control (e.g., Git) for
  reproducibility.
+ Use `conda env export --from-history' to export only explicitly
  installed packages (avoids unnecessary dependencies).

* Update environments safely
Avoid breaking dependencies by updating packages carefully.

Update all packages in the environment:

~conda update --all~  # This is /not/ recommended by NSC!

Update a specific package:

~conda update numpy~

*Best Practice:*
+ Test updates in a staging environment before applying them to
  production.
+ Use `conda list' to check installed versions before updating.

* Remove unused environments
Clean up old environments to save disk space.

List all environments:

~conda env list~

Remove an environment:

~conda env remove --name old_env~

*Best Practice:*
+ Regularly prune unused environments (`conda clean --all' removes
  cached packages).

* Use conda-forge for additional packages
Prefer conda-forge for community-maintained packages.

Add conda-forge as a channel:

~conda config --add channels conda-forge~

Install a package from conda-forge:

~conda install some_package~

*Best Practice:*
+ Prioritize conda-forge over the default Anaconda channel for
  broader package availability.

* Avoid mixing conda and pip
If you must use pip, install it first in the Conda environment.

~conda install pip~ 

~pip install some_pip_package~

*Best Practice:*
+ Prefer Conda packages when possible to avoid conflicts.
+ If using pip, document it in environment.yml under `pip:'.

# According to NSC you should /never/ install packages using conda
# /after/ you have used pip. Do /all/ conda (mamba) installs before
# using pip!

* Use `conda clean' regularly
Remove unused packages and caches to free up space.

~conda clean --all~

*Best Practice:*
+ Run this periodically to keep your Conda installation lean.

* Use environment variables for paths
Set environment variables to avoid hardcoding paths.

Set a variable in the current shell:

~export MY_DATA_DIR=/path/to/data~

Or set it in the Conda environment:

~conda env config vars set MY_DATA_DIR=/path/to/data~

~conda activate my_project~

**Best Practice:**
+ Use `.env` files for project-specific variables (load them with
  `python-dotenv`).

* Use mamba for faster dependency resolution
Mamba is a drop-in replacement for Conda that resolves dependencies
much faster.

Install mamba:

~conda install mamba -n base -c conda-forge~

Use mamba instead of conda:

~mamba install numpy pandas~

*Best Practice:*
+ Use mamba for large environments to speed up installation.

* Document dependencies clearly
Include a README.md in your project with:
- Environment setup instructions.
- Key dependencies.
- How to activate the environment.

* Example Workflow
** Create environment
~conda create --name my_project python=3.9~

~conda activate my_project~

** Install packages
~conda install numpy pandas scikit-learn~

~pip install some_pip_package~

** Export environment
~conda env export --from-history > environment.yml~

** Share environment
Share environment.yml and README.md with collaborators.

####################################################################

I hope this is readable.

Note that some advice above is /not/ good practice according to the
instructions supplied by NSC and NCS provides plausible motivation
for their advice.

https://nsc.gitlab-pages.liu.se/berzelius-training/managing-conda-environments-best-practices/2.%20best-practices/

I have tested none of this so far. The weather has been too nice :-)

/Martin

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.python


csiph-web