Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@marcogullieuszik
Last active October 11, 2017 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcogullieuszik/30f1ce4e7381b6347d99563ff47d6ccc to your computer and use it in GitHub Desktop.
Save marcogullieuszik/30f1ce4e7381b6347d99563ff47d6ccc to your computer and use it in GitHub Desktop.
How to install Python with conda

Introduction

It is not always easy to have a working Python environment with all packages and librearies that are needed. The easiest way, in particolar for users not familiar with Python and Linux system managment, is to use Anaconda

Anaconda® is a package manager, an environment manager, a Python distribution, and a collection of over 720 open source packages. It is free and easy to install, and it offers free community support.

conda is the package manager

The conda command is the primary interface for managing Anaconda installations. It can query and search the Anaconda package index and current Anaconda installation, create new conda environments, and install and update packages into existing conda environments.

Anaconda includes conda, conda-build, Python, and over 150 automatically installed scientific packages and their dependencies. As with Miniconda, over 250 additional scientific packages can be installed individually with the “conda install” command.

Miniconda is a small “bootstrap” version that includes only conda, Python, and the packages they depend on. Over 720 scientific packages and their dependencies can be installed individually from the Continuum repository with the “conda install” command.

Install miniconda

Before starting you should read https://conda.io/docs/download.html

I suggest not to download the full Anaconda, but start with miniconda and then install only what you really need.

To install you have to download the latest Anaconda installer bash script and then run it.

Download

Download the miniconda installer for Python3 at https://conda.io/miniconda.html.
Let's assume that you downloaded the installer script file Miniconda3-latest-Linux-x86_64.sh

If you really need to use Python2.7 you can download the corresponding version. To date (2017), most packages works with Python2.7, but most likely in a few years Python2 will not be supported. It is therefore better to start using Python3.

Install

It is possible to install Anaconda/miniconda as root, but I suggest to install with no root privileges in your home directory to avoid conflicts with the system and other users

bash Miniconda3-latest-Linux-x86_64.sh 

follow the instructions and you will have miniconda installed on your system!

setup paths

You should let the installer add the conda installation of Python to your PATH environment variable. This works only if you are using a Bash-like shell. If you are using csh or tcsh, just add the following like to your .cshrc file

# miniconda
set path =($HOME/miniconda3/bin $path)

update

You can now check if you are using the latest version

conda update conda

You will probably obtain an output like this

Fetching package metadata .........
Solving package specifications: .

Package plan for installation in environment /home/marco/miniconda3:

The following packages will be UPDATED:

    conda: 4.3.21-py36_0 --> 4.3.22-py36_0

Proceed ([y]/n)? y

press "y" to confirm

If there are no updates the output will be like this:

Fetching package metadata .........
Solving package specifications: .

# All requested packages already installed.
# packages in environment at /home/marco/miniconda3:
#
conda                     4.3.22                   py36_0  

Installing Python packages

Read the docs at https://conda.io/docs/index.html

You now need to install all packages that we need. Let's will start with:

  • numpy
  • scipy
  • matplotlib
  • astropy
  • jupyter-notebook

With conda you can install all of them with the command

conda install numpy scipy matplotlib astropy notebook

conda will then list all the packages and dependences what will be installed. Press y to proceed.

astroquery

astroquery is a set of tools for querying astronomical web forms and databases.
It is an affiliated package of astropy and can be installed with conda from the astropy channel:

conda install -c astropy astroquery

Jupyter Widgets

Notebooks come alive when interactive widgets are used. Users can visualize and control changes in the data.

user Guide

installation guide

conda install -c conda-forge ipywidgets
jupyter nbextension enable --py widgetsnbextension

Uninstall Anaconda

Read the doc https://docs.continuum.io/anaconda/install/uninstall

To uninstall Anaconda, you can do a simple remove of the program. This will leave a few files behind, which for most users is just fine.

Remove the entire Anaconda directory, which has a name such as anaconda2 or anaconda3, by entering e.g.

rm -rf ~/anaconda3

If you use Linux or macOS, you may also wish to check the .bashrc file in your home directory for a line such as:

export PATH="/home/marco/miniconda3/bin:$PATH"

After uninstalling Anaconda, you may delete this line and save the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment