python_anaconda.rst 3.37 KB

Installing Python with Anaconda

Anaconda is an environment of development well designed for science use. Any version of Python can be installed using virtual environments. Spyder is a code editor allowing an easy write and execution of Python code. Jyputer Notebook allos to create nice tutorials.

Informations about Anaconda.

1. Virtual environments of Anaconda

If you want to create a project named my_project that uses GuitAstro, we recommand to create a virtual environment (my_project) to not disturb other Python applications.

We define two kind of prompts in the command shell:

  • $ = prompt of the normal environment
  • (my_project) $ = prompt of the virtual environment named my_project

To create the virtual environment my_project with Python version 3.7 and Spyder:

$ conda create -n my_project python=3.7 spyder

To use the virtual environment my_project. The prompt changes:

$ conda activate my_project
(my_project) $

After installation of Anaconda default virtual environment can be accessed: (base). One can go anywhere in the disk with this environment and build application with Python 3.7.

When we want to quit the virtual environment

(my_project) $ conda deactivate $

In virtual environments Python is launched using command python. For example:

$ conda activate my_project
(my_project) $ python

Now, pip will install packages only in the selected virtual environment.

Spyder of virtual environment my_project can be called as:

$ conda activate my_project
(my_project) $ spyder

Sometimes, in Linux, Spyder enconter a conflict of libstdc++.so.6. If Spyder crashes at launch, simply remove the file ~/anaconda3/lib/libstdc++.so.6. For example:

mv ~/anaconda3/lib/libstdc++.so.6 ~

2. Linux installation of Anaconda

$ cd
$ wget https://repo.anaconda.com/archive/Anaconda3-5.3.1-Linux-x86_64.sh
$ bash Anaconda3-5.3.1-Linux-x86_64.sh

Answer to questions by yes. At the end, you must make updates:

$ source .bashrc
$ conda update --all
(base) $

At the end, the prompt indicates we are in the (base) virtual environment.

Now you can create any virtual environment you want.

To launch Spyder of a given virtual environment (my_projet) you can create an icon on desktop. In case of Gnome Ubuntu:

$ cd
$ cd Desktop
$ gedit spyder_base.desktop

[Desktop Entry]
Name=Spyder base
Exec="/home/xxx/anaconda3/envs/my_project/bin/spyder"
Icon=/home/xxx/anaconda3/envs/my_project/share/icons/spyder3.png
Type=Application
Terminal=false
Categories=Development;Application

Note: Destop is called Bureau in French version.

A grayed icon appears on the desktop. You must activate is with the contextual menu item Allow execution".

3. Windows installation of Anaconda

Link for download Anaconda (all operating systems).

Follow the standard installation.

After the installation, before using python you must set paths in environment variables: