简体   繁体   中英

When using a conda environment, how can I set environment variables similarly to module load?

I am trying to fill configuration files so I can port a large model. The normal way to do this, as recommended by the documentation, is write a shell script with eg module load openmpi, module load.netcdf and so on. This would normally then add the relevant paths to PATH, MANPATH, LIBRARY_PATH, MPI_RUN etc. However, because I am on a shared server and cannot add the necessary packages to the list available to be loaded, this option is not possible.

I have a conda environment with all the correct packages setup. Looking at the result of printenv, conda does not itself add anything to PATH, MANPATH etc. That said, I'll admit I'm not completely sure how conda works behind the scenes.

Is there some neat trick where I can add these packages paths to all the environment variables, or do I have to add them all manually?

Thank you!

You can add the paths to the necessary environment variables manually in your shell script or in your environment setup script (eg .bashrc or.bash_profile).

To do this, you can use the " export " command to set the value of an environment variable. For example:

export PATH="/path/to/package1:/path/to/package2:$PATH"
export MANPATH="/path/to/manpages:/path/to/manpages2:$MANPATH"
export LIBRARY_PATH="/path/to/library:/path/to/library2:$LIBRARY_PATH"
export MPI_RUN="/path/to/mpirun:/path/to/mpirun2:$MPI_RUN"

You can also use the " conda info " command to get the paths of packages installed in your conda environment. For example:

conda info --envs
# Lists all available conda environments

conda list -n myenv
# Lists all packages installed in the environment "myenv"enter code here

You can then use these paths in the " export " commands to set the values of the environment variables.

Keep in mind that these changes will only be applied to your current shell session. If you want these changes to be persistent, you will need to add these commands to your environment setup script (eg .bashrc or.bash_profile) so that they are run every time you start a new shell session.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM