Work Environment: Conda - ramirezfranciscof/aiida-core GitHub Wiki
This installation route installs all necessary software – including the prerequisite services PostgreSQL and RabbitMQ – into a Conda environment.
First we install the prerequisite services + AiiDA (core)
conda create -n aiida -c conda-forge aiida-core aiida-core.services
conda activate aiida
reentry scan
Then we need to initialize a database storage area on disk.
initdb -D mylocal_db
This database cluster may contain a collection of databases (one per profile) that is managed by a single running server process. We start this process with:
pg_ctl -D mylocal_db -l logfile start
Then, start the RabbitMQ server:
rabbitmq-server -detached
Finally, start the AiiDA daemon(s) [example below starts 2 of them]:
verdi daemon start 2
Shut-down services
After finishing with your aiida session, particularly if switching between profiles, you may wish to power down the services:
verdi daemon stop
pg_ctl stop
Deactivate base autoload
It is possible that conda will set things up so that the default "base" environment is loaded upon logging into the computer. If you wish to disable that option, you can run [1]:
conda config --set auto_activate_base false
The first time you run it, it'll create a ./condarc in your home directory with that setting to override the default.
List environments
$ conda env list
# conda environments:
#
myenv /home/username/miniconda/envs/myenv
snowflakes /home/username/miniconda/envs/snowflakes
bunnies /home/username/miniconda/envs/bunnies
List packages in environment
$ conda list -n myenv
# packages in environment at /home/framirez/miniconda3/envs/aiida-tutorial:
#
# Name Version Build Channel
_libgcc_mutex 0.1 main
_openmp_mutex 4.5 1_gnu
alabaster 0.7.12 pypi_0 pypi
anyio 3.2.0 pypi_0 pypi
appdirs 1.4.4 pypi_0 pypi
argon2-cffi 20.1.0 pypi_0 pypi
async-generator 1.10 pypi_0 pypi
attrs 21.2.0 pypi_0 pypi
(...)
You can just run conda list to show the ones in the currently loaded environment.
Install pip in environment
$ conda install -n myenv pip
We recommend that you:
-
Use pip only after conda: Install as many requirements as possible with
condathen usepip. Pip should be run with--upgrade-strategy only-if-needed(the default). Do not use pip with the--userargument, avoid all users installs -
Use conda environments for isolation: Create a conda environment to isolate any changes pip makes. Environments take up little space thanks to hard links. Care should be taken to avoid running pip in the root environment.
-
Recreate the environment if changes are needed: Once pip has been used, conda will be unaware of the changes. To install additional conda packages, it is best to recreate the environment.
-
Store conda and pip requirements in text files: Package requirements can be passed to conda via the
--fileargument. Pip accepts a list of Python packages with-ror--requirements. Conda env will export or create environments based on a file with conda and pip requirements.
Removing environments
$ conda env remove --name myenv
Sources
[1] https://stackoverflow.com/questions/54429210/how-do-i-prevent-conda-from-activating-the-base-environment-by-default [2] https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#viewing-a-list-of-your-environments
Older information
$ conda deactivate
$ conda env remove -n ENV_NAME
# Alternative
$ conda remove --name myenv --all
# Check
$ conda info --envs
https://conda.io/projects/conda/en/latest/user-guide/getting-started.html
Where to set activation and deactivation env variables
cd $CONDA_PREFIX
mkdir -p ./etc/conda/activate.d
mkdir -p ./etc/conda/deactivate.d
touch ./etc/conda/activate.d/env_vars.sh
touch ./etc/conda/deactivate.d/env_vars.sh
How to set them in ./etc/conda/activate.d/env_vars.sh:
#!/bin/sh
export MY_KEY='secret-key-value'
export MY_FILE=/path/to/my/file/
How to unset them in ./etc/conda/deactivate.d/env_vars.sh:
#!/bin/sh
unset MY_KEY
unset MY_FILE
Export environment:
$ conda env export > environment.yml
# Import
$ conda env create -f environment.yml
Set during creation or in multiple steps:
conda create -n myenv scipy=0.15.0
# EQUIVALENT
conda create -n myenv python
conda install -n myenv scipy=0.15.0
Others...
conda create -n myenv python=3.4 scipy
conda create -n myenv python=3.4
conda install -n myenv scipy
https://docs.conda.io/projects/conda/en/4.6.1/user-guide/index.html