You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: notebooks/installing_Python.md
+62-32Lines changed: 62 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,22 +22,22 @@ For this course, we will use Miniconda which allows us to manage Python packages
22
22
4. First, make sure you have the latest version of **conda** installed. To do this, type the following command:
23
23
24
24
```
25
-
> conda update conda
25
+
conda update conda
26
26
```
27
27
and update if necessary (👉 tip: do this often).
28
28
29
29
5. If you have been paying attention, you will see that the current line in the console says "base" in parentheses. This means that you are in a Python environment called "base". A wise strategy is to not install anything in this environment other than the standard Python libraries that have already been added during the Miniconda installation process. If you are curious, you can see which libraries these are by entering the command ``conda list``. Our strategy here will be to create a new Python environment called "course" and install there all the scientific libraries that we will use during the course. To do this, we will enter the following command:
30
30
31
31
```
32
-
> conda create --name course python
32
+
conda create --name course python
33
33
```
34
34
35
35
6. Once finished, use the command ``conda env list`` and you will see two environments listed, "base" and "course", and an asterisk indicating that "base" is the currently active environment. To install the Python libraries needed in the "course" environment, we need to activate it first, so we type ``activate course``. Now you will see the word "course" in parentheses, indicating that "course" is now the active environment.
36
36
37
37
7. Next, we proceed to install the libraries needed for the course. Instead of doing it one by one, we will do it in a single line as follows (you can paste and copy the command directly into your console)
and say yes to all. Conda will install the chosen libraries/packages and all the necessary dependencies. Once finished, you're done.
@@ -71,33 +71,31 @@ We will learn how to use Jupyter Lab properly during the course.
71
71
The following are the basic commands for installing, removing and and keep your Python libraries up to date.
72
72
73
73
```markdown
74
-
list all Python packages and the versions installed in a specific environment:
75
-
> conda list
74
+
# list all Python packages and the versions installed in a specific environment:
75
+
conda list
76
76
77
-
install a new package in a specific environment:
78
-
> conda install <name(s) of the package(s)>
77
+
# install a new package in a specific environment:
78
+
conda install <nameofthepackage-s>
79
79
80
-
uninstall a package
81
-
> conda remove <nameofthepackage>
80
+
# uninstall a package
81
+
conda remove <nameofthepackage>
82
82
83
-
update a specific package
84
-
> conda update <nameofthepackage>
83
+
# update a specific package
84
+
conda update <nameofthepackage>
85
85
86
-
update all packages in the environment ensuring compatibility
87
-
> conda update --all
86
+
# update all packages in the environment ensuring compatibility
87
+
conda update --all
88
88
89
-
clean all outdated packages (by default conda does not delete
90
-
previous versions of packages/libraries when upgrading).
91
-
> conda clean --all
89
+
# clean all outdated packages (by default conda does not delete
90
+
# previous versions of packages/libraries when upgrading).
91
+
conda clean --all
92
92
```
93
93
94
94
95
95
96
96
97
97
## More on conda/Python environments
98
98
99
-
TODO
100
-
101
99
Environments enables you to have multiple versions of Python or scientific packages installed on your computer at the same time. This is useful, for example, to test a script on different versions of Python and any other Python library, or to keep separate different scientific libraries that may work with different Python versions, etc.
102
100
103
101
```
@@ -116,25 +114,56 @@ to create a new environment using conda the general procedure is as follows (in
116
114
some examples below
117
115
118
116
```markdown
119
-
create an environment named "main" with the last version of Python supported by conda
120
-
>conda create --name main python
117
+
# create an environment named "main" with the last version of Python supported by conda
118
+
conda create --name main python
121
119
122
-
create an environment with a specific version of Python
123
-
>conda create --name new_env python=3.8.1
120
+
# create an environment with a specific version of Python
121
+
conda create --name new_env python=3.8.1
124
122
125
-
create an environment named "SCIENV" with the libraries numpy, scipy, matplolib and jupyterlab (conda will take care of including all the necessary dependencies)
# create an environment named "SCIENV" with the libraries numpy, scipy, matplolib and jupyterlab (conda will take care of including all the necessary dependencies)
create an environment named "image" with the library scikit-image and all the neccesary dependencies
129
-
>conda create --name image scikit-image
126
+
# create an environment named "image" with the library scikit-image and all the neccesary dependencies
127
+
conda create --name image scikit-image
130
128
131
-
remove an existing environment (make sure you are not in the environment you want to remove)
132
-
>conda env remove --name <ENVNAME>
129
+
# remove an existing environment (make sure you are not in the environment you want to remove)
130
+
conda env remove --name <ENVNAME>
133
131
```
134
132
133
+
More info here: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html
134
+
135
+
### Adding Python packaged from other channels or via pip in conda
135
136
137
+
At some point, you are likely to find yourself in the situation where you want to install a Python package that is not in the official (default) conda channel, and you need to install it using pip, the standard Python installation package, or the community-driven _conda-forge_ channel. In this case, it is strongly recommended to create a new Python environment and, in particular, never use pip to install packages into the Python environments you have for general use, as this may break compatibility between different versions of the environment.
138
+
139
+
#### Case 1: Python package installed using pip
140
+
141
+
Create a new Python environment and install the package and any necessary dependencies. Follow the developer's installation instructions.
142
+
143
+
#### Case 2: the Python package is in the conda-forge channel
144
+
145
+
To install packages from the _conda-forge_ community channel, you must first activate it (see instructions below). Once this is done, create your new Python environment and install all the necessary libraries using conda.
146
+
147
+
To add the _conda-forge_ channel use:
148
+
149
+
```markdown
150
+
conda config --append channels conda-forge
151
+
```
152
+
153
+
> [!WARNING]
154
+
> In most tutorials you can find on the internet you will find the following line to enable the conda-forge channel: ``conda config --add channels conda-forge``. **We advise you not to do this**. This will make conda-forge the priority channel in your Python installation. Your anaconda's default channel will have a lower priority, and some of your packages will start upgrading to conda-forge, affecting other environments as well. Using ``--append`` instead of ``--add`` will keep your default conda channel high in priority, and package versions will be searched on your default before going to conda-forge. If you have already made a mess of it, you can use the following lines:
155
+
>
156
+
> ```markdown
157
+
> # show channels
158
+
> conda config --show channels
159
+
>
160
+
> # describe channel priority
161
+
> conda config --describe channel_priority
162
+
>
163
+
> # remove conda-forge
164
+
> conda config --remove channels conda-forge
165
+
> ```
136
166
137
-
More info here: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html
138
167
139
168
### Using environment.ylm (YALM) files
140
169
@@ -146,15 +175,16 @@ These files are a useful way to share Python environments and ensure, for exampl
146
175
147
176
To create a conda environment using an ``environment.ylm`` file from the command lines use (if you are in the folder containing the ``environment.ylm`` otherwise you will have to specify the path)
148
177
149
-
``>conda env create -f environment.yml``
178
+
``conda env create -f environment.yml``
150
179
151
180
This will create a new conda environment called with the name defined within the ``environment.ylm`` file.
152
181
153
182
To create an ``environment.ylm`` file from a specific conda environment do as follows
154
183
155
184
```markdown
156
-
>conda activate <ENVNAME>
157
-
>conda env export > environment.yml
185
+
conda activate <environment name>
186
+
187
+
conda env export > environment.yml
158
188
```
159
189
160
190
This command will export the list of packages and their versions that are installed in the current active conda environment so that you can quickly share it with anyone.
0 commit comments