Skip to content

Commit 1e9fd0b

Browse files
committed
Update installing_Python.md
1 parent d25233f commit 1e9fd0b

1 file changed

Lines changed: 62 additions & 32 deletions

File tree

notebooks/installing_Python.md

Lines changed: 62 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ For this course, we will use Miniconda which allows us to manage Python packages
2222
4. First, make sure you have the latest version of **conda** installed. To do this, type the following command:
2323

2424
```
25-
> conda update conda
25+
conda update conda
2626
```
2727
and update if necessary (👉 tip: do this often).
2828

2929
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:
3030

3131
```
32-
> conda create --name course python
32+
conda create --name course python
3333
```
3434

3535
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.
3636

3737
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)
3838

3939
```
40-
>conda install numpy scipy pandas matplotlib jupyterlab
40+
conda install numpy scipy pandas matplotlib jupyterlab
4141
```
4242

4343
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.
7171
The following are the basic commands for installing, removing and and keep your Python libraries up to date.
7272

7373
```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
7676

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 <name of the package-s>
7979

80-
uninstall a package
81-
> conda remove <name of the package>
80+
# uninstall a package
81+
conda remove <name of the package>
8282

83-
update a specific package
84-
> conda update <name of the package>
83+
# update a specific package
84+
conda update <name of the package>
8585

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
8888

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
9292
```
9393

9494

9595

9696

9797
## More on conda/Python environments
9898

99-
TODO
100-
10199
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.
102100

103101
```
@@ -116,25 +114,56 @@ to create a new environment using conda the general procedure is as follows (in
116114
some examples below
117115

118116
```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
121119

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
124122

125-
create an environment named "SCIENV" with the libraries numpy, scipy, matplolib and jupyterlab (conda will take care of including all the necessary dependencies)
126-
>conda create --name SCIENV numpy scipy matplotlib jupyterlab
123+
# create an environment named "SCIENV" with the libraries numpy, scipy, matplolib and jupyterlab (conda will take care of including all the necessary dependencies)
124+
conda create --name SCIENV numpy scipy matplotlib jupyterlab
127125

128-
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
130128

131-
remove an existing environment (make sure you are not in the environment you want to remove)
132-
>conda env remove --name <ENV NAME>
129+
# remove an existing environment (make sure you are not in the environment you want to remove)
130+
conda env remove --name <ENV NAME>
133131
```
134132

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
135136

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+
> ```
136166
137-
More info here: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html
138167
139168
### Using environment.ylm (YALM) files
140169
@@ -146,15 +175,16 @@ These files are a useful way to share Python environments and ensure, for exampl
146175
147176
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)
148177
149-
``>conda env create -f environment.yml``
178+
``conda env create -f environment.yml``
150179
151180
This will create a new conda environment called with the name defined within the ``environment.ylm`` file.
152181
153182
To create an ``environment.ylm`` file from a specific conda environment do as follows
154183
155184
```markdown
156-
>conda activate <ENV NAME>
157-
>conda env export > environment.yml
185+
conda activate <environment name>
186+
187+
conda env export > environment.yml
158188
```
159189
160190
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

Comments
 (0)