Wiki source code of Installing packages with Conda

Last modified by Mikko Halmela on 2024/02/14 09:29

Show last authors
1 Cubbli user does not usually have administrator privileges that would allow them to install packages (such as libraries and software for development) without manually building them from source and managing a bunch of dependencies, or contacting IT support.
2 In this manual we offer an alternative:
3
4 **Conda**, a language agnostic virtual environment and package manager. It's repositories have packages from multiple languages, but you might be most interested in **Python**, **R** and **Java**.
5
6 \\
7
8 Well how does one use it?
9
10 === Basic usage ===
11
12 ~1. Make sure that the desired package is available on {{code language="none"}}conda{{/code}}:
13
14 [[https:~~/~~/anaconda.org/anaconda/repo>>url:https://anaconda.org/anaconda/repo||shape="rect"]] or
15
16 {{{conda search package}}}
17
18 \\
19
20 2. Make a directory for the project (you can and use a different name) and go there:
21
22 \\
23
24 {{{mkdir projectcd project}}}
25
26 \\
27
28 3. Create a virtual environment:
29
30 {{{conda create -yn project}}}
31
32 Virtual environment is not dependent on the directory, and thus does not need to have a same name.
33 If for some reason the name of your environment is lost, you can list them with
34
35 {{{conda info --envs}}}
36
37 \\
38
39 4. Activate the virtual environment
40
41 {{{conda activate project}}}
42
43 \\
44
45 5. Install the desired packages
46
47 \\
48
49 {{{conda search packageconda install package}}}
50
51 Some packages have their own instructions. They usually happen at this point and you should follow them.
52
53 Note that his might take a long time. It is rather opaque operation (especially "Solving environment"), so you kind of just have to trust it and wait, maybe grab a cup of coffee.
54
55 \\
56
57 6. Do what you want
58
59 \\
60
61 7. Close the virtual environment
62
63 {{{conda deactivate}}}
64
65 Later when you revisit the project, you can just activate the virtual environment, develop and deactivate.
66
67 It is a good practice to create own virtual environments for each project, because handling dependencies can be quite a mess. Sometimes though it can be easier to use same environment multiple times, if the dependencies do not change. In that case the environment's name should reflect it's use cases.
68
69 === Sharing ===
70
71 If you want to share your environment, you can export it with
72
73 {{{conda env export --name project > environment.yml}}}
74
75 The receiver should create a own directory (perhaps you can also share the whole directory) for the project, put {{code language="none"}}environment.yml{{/code}} there, go there and create {{code language="none"}}conda{{/code}} environment with
76
77 {{{conda env create }}}
78
79 === Deleting ===
80
81 You can delete your virtual environment and all the packages alongside it with
82
83 {{{conda remove --name project --all}}}
84
85 === Changing channels ===
86
87 By default {{code language="none"}}conda{{/code}} uses official Anaconda repositories, but sometimes they don't have the desired packages. In that case, turning to community managed channels, such as [[conda-forge>>url:https://conda-forge.org||shape="rect"]] or [[bioconda>>url:https://bioconda.github.io/||shape="rect"]], might help.
88
89 If you know that a package is in a channel, you can install it with
90
91 {{{conda install -c channel package}}}
92
93 \\
94
95 === Parting words ===
96
97 If you want to know {{code language="none"}}conda{{/code}} better, good place to start is their documentation: [[https:~~/~~/docs.conda.io/projects/conda/en/latest/user-guide/index.html>>url:https://docs.conda.io/projects/conda/en/latest/user-guide/index.html||shape="rect"]]
98 Cheat sheet of {{code language="none"}}conda{{/code}}'s main commands: [[https:~~/~~/docs.conda.io/projects/conda/en/latest/_downloads/843d9e0198f2a193a3484886fa28163c/conda-cheatsheet.pdf>>url:https://docs.conda.io/projects/conda/en/latest/_downloads/843d9e0198f2a193a3484886fa28163c/conda-cheatsheet.pdf||shape="rect"]]
99 List of available Anaconda/default/official packages: [[https:~~/~~/anaconda.org/anaconda/repo>>url:https://anaconda.org/anaconda/repo||shape="rect"]] 
100 Note that Anaconda maintains its own repositories, so the latest versions of your software may or may not be available there.
101
102 An alternative ([[better or worse?>>url:https://stackoverflow.com/a/67082504||shape="rect"]]) for conda when using Python are its own tools venv (virtual environment) and pip (package manager). Using them is mostly the same as with {{code language="none"}}conda{{/code}}, but as it is not language agnostic, their usage is not elaborated here (but [[here>>doc:Cubbli.User documentation.Installing Python modules with Virtual Environment.WebHome]]). Other languages, such as Rust, have their own package managers too, and they should be preferred over using Conda, since they most likely have the most recent versions of each package. Learning and using these is left as an exercise for the reader.
103
104 \\
105
106 If you want to send regards, critiques, corrections, topics for manuals or anything else really, use the comment box below or contact me personally. You can find my contact info on my profile.
107
108 \\