• Active Topics 

Install Python Anaconda and Use IPython Notebbok

Including Cython, Jython, IronPython, PyPy, Django framework, and interpreters: Ipython, IPython Jupyter/Notebook, CPython


Post Reply
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5211
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#1

See the quickest way to install Anaconda in the next post (post #2).

Python Anaconda is a completely free Python distribution. It includes more than 400+ of the most popular Python packages for science, statistics, mathematics, engineering, and data analysis.

To install Anaconda package go to https://www.continuum.io/downloads and download the package installer that is compatible with your system.

For Ubuntu Linux, assume the downloaded installer is in the Downloads directory, then go to the terminal (Ctrl + Alt + T) and move to the directory where the installer is

Code: Select all

$ cd ~/Downloads
To install, execute

Code: Select all

bash Anaconda-4.x.x-Linux-x86.sh
chmod +x Anaconda-4.x.x-Linux-x86.sh
./Anaconda-4.x.x-Linux-x86.sh
Replace 4.x.x by the proper version, mostly current, agree with the licence terms and conditions and continue. By default Anaconda will be installed in your home directory.

To use for example IPython Notebook from Anaconda (Anaconda is a default virtual environment) and not system Python, move to the directory and activate Anaconda by executing

Code: Select all

cd ~/anaconda/
~/anaconda$ source bin/activate ~/anaconda/
Clear terminal and while you're still in anaconda directory, check whether Python and IPython you're going to use come from Anaconda

Code: Select all

~/anaconda$ which ipython

Code: Select all

~/anaconda$ which python
Finally, exit, and type

Code: Select all

~/anaconda$ jupyter notebook
This will take you to IPython/Jupyter Notebook.
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5211
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#2

The procedure below utilizes bash scripts which is a fastest way to install anaconda. It works on Ubuntu LTS: 12.04, 14.04 and 16.04. Installing Python from anaconda is very useful especially for fresh installs. If you have installed python packages the other way rather than from anaconda, you are likely to get errors such

Code: Select all

/home/user/.local/lib/python2.7/site-packages/healpy/_sphtools.so: undefined symbol: PyFPE_jbuf
or

Code: Select all

undefined symbol: PyFPE_jbuf
when installing Python dependencies such as Numpy, Scipy or Healpy, which may be a result of conflicts between system python and/or conda-forge installed packages and those installed with pip, for example conflict between two versions of numpy where one is installed with conda and another one with pip.

These errors are usually due to an environment conflict. It happens that you build packages and all your include paths point to system python /usr/local/lib/python2.7/dist-packages/some_package and yet you use python from ~/anaconda/lib/python2.7/. One way to solve this problem may need uninstalling and re-installing packages but a permanent and recommended solution is to use virtual environments, virtualenv.

Depending on which version of Python you are interested (Python 2 or Python 3), choose the appropriate procedure below.

Install Anaconda for Python 2

# Move to home directory:

Code: Select all

cd ~
Download anaconda for Python 2 (You can change what anaconda version you want at Continuum repository)

Code: Select all

 wget https://repo.continuum.io/archive/Anaconda2-5.0.1-Linux-x86_64.sh
and then:

Code: Select all

bash Anaconda2-5.0.1-Linux-x86_64.sh -b -p ~/anaconda
rm Anaconda2-5.0.1-Linux-x86_64.sh
echo 'export PATH="~/anaconda/bin:$PATH"' >> ~/.bashrc
-b -p ~/anaconda tells the installation that the destination folder is anaconda in the HOME directory.

Refresh:

Code: Select all

source .bashrc
conda update conda

Install Anaconda for Python 3:

Go to home directory

Code: Select all

cd ~
Download anaconda for Python 3 (You can change what anaconda version you want at Continuum repository):

Code: Select all

wget https://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh
and then:

Code: Select all

bash Anaconda3-5.0.1-Linux-x86_64.sh -b -p ~/anaconda
rm Anaconda3-5.0.1-Linux-x86_64.sh
echo 'export PATH="/home/user/anaconda/bin:$PATH"' >> ~/.bashrc #Set PYTHONPATH environment variable


Refresh:

Code: Select all

source .bashrc

conda update conda
The files are from the Anaconda distribution installer archive.
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5211
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#3

Deleting Anaconda

It suffices to delete anaconda by just

Code: Select all

rm -rf ~/anaconda

but also it is good to remove the hidden .condarc file and .conda and .continuum directories which may have been created in the home directory with rm -rf ~/.condarc ~/.conda ~/.continuum, more clearly:

Code: Select all

rm -rf ~/anaconda
rm -rf ~/.anaconda/navigator
rm -rf ~/.condarc ~/.conda ~/.continuum

The anaconda installer adds a line in your ~/.bash_profile or ~/.bashrc script that prepends the anaconda bin directory to your $PATH environment variable. Deleting the anaconda directory should be all you need to do, but it's customary housekeeping to remove this line from your setup script too.

So open and edit ~/.bashrc or ~/.bash_profile (nano or vim ~/.bashrc) and remove the anaconda directory from your PATH environment variable, it looks like

export PATH="/home/user/anaconda2/bin:$PATH"

Finally reload the ~/.bashrc file by executing

Code: Select all

source ~/.bashrc

See other options for safely uninstalling anaconda here.
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5211
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#4

You can update conda by running:

$ conda update -n base conda
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5211
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#5

Download the latest version of Anaconda distribution for Linux (64-bit)

  1. wget https://repo.anaconda.com/archive/Anaconda3-5.3.1-Linux-x86_64.sh


and follow these instructions to install it.

After installation update all packages including conda with

  1. conda update -n base -c defaults conda


or

  1. conda update --all

0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5211
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#6

If you get the error below,

  1. RuntimeError: latex was not able to process the following string:
  2. b'lp'
  3.  
  4. Here is the full report generated by latex:
  5. This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian) (preloaded format=latex)
  6.  restricted \write18 enabled.
  7. entering extended mode
  8.  
  9. (/home/elimboto/.cache/matplotlib/tex.cache/b4f42faf303693cf76478f1510b3335e.te
  10. x
  11. LaTeX2e <2017-04-15>
  12. Babel <3.18> and hyphenation patterns for 3 language(s) loaded.
  13. (/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
  14. Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
  15. (/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
  16. (/usr/share/texlive/texmf-dist/tex/latex/type1cm/type1cm.sty)
  17.  
  18. ! LaTeX Error: File `type1ec.sty' not found.
  19.  
  20. Type X to quit or <RETURN> to proceed,
  21. or enter new name. (Default extension: sty)
  22.  
  23. Enter file name:
  24. ! Emergency stop.
  25. <read *>
  26.        
  27. l.6 \usepackage
  28.               {type1ec}^^M
  29. No pages of output.
  30. Transcript written on b4f42faf303693cf76478f1510b3335e.log.
  31.  


which suggests that Python is unable to render LaTeX in Matplotlib, install the packages as indicated below:

  1. sudo apt-get install dvipng texlive-latex-extra texlive-fonts-recommended cm-super

0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5211
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#7

Install Anaconda Distribution on Linux in 2023

1. Update system repositories:

  1. sudo apt-get update

2. Install curl package - used to fetch the installation script for Anaconda:

  1.  sudo apt-get install curl -y

3. Prepare Anaconda Installer - switch to /tmp and make it a present working directory:

4. Utilize the following “curl” command to download the Anaconda installer script. Also, make sure you download the latest version by firstly visiting their official archive site:

  1. curl --output anaconda.sh https://repo.anaconda.com/archive/Anaconda3-2023.03-1-Linux-x86_64.sh

5. Check that “SHA-256” checksum of the downloaded Anaconda script matches the one displayed on the official site:

  1. sha256sum anaconda.sh


6. Install Anaconda on Ubuntu Linux (In this case Ubuntu 22.04) - run the downloaded Anaconda installer script:

  1. bash anaconda.sh


The Anaconda installation wizard will appear on the terminal; Please, press ENTER to continue.

Carefully read the Anaconda End User License Agreement.

When you see "--More--" keep pressing Enter until you see

  1. Do you accept the license terms? [yes|no]
  2. [no] >>>
  3. Please answer 'yes' or 'no':'
  4. >>>


and then type “yes” to move ahead:

  1. Anaconda3 will now be installed into this location:
  2. /home/user/anaconda3
  3.  
  4.   - Press ENTER to confirm the location
  5.   - Press CTRL-C to abort the installation
  6.   - Or specify a different location below


Press Enter to confirm.

You see something like this:

  1. [/home/user/anaconda3] >>>
  2. PREFIX=/hom/user/anaconda3
  3. Unpacking payload ...
  4.                                                                                
  5. Installing base environment...
  6.  
  7.  
  8. Downloading and Extracting Packages
  9.  
  10.  
  11. Downloading and Extracting Packages
  12.  
  13. Preparing transaction: done
  14. Executing transaction: |
  15.  
  16.     Installed package of scikit-learn can be accelerated using scikit-learn-intelex.
  17.     More details are available here: https://intel.github.io/scikit-learn-intelex
  18.  
  19.     For example:
  20.  
  21.         $ conda install scikit-learn-intelex
  22.         $ python -m sklearnex my_application.py
  23.  
  24.    
  25.  
  26. done
  27. installation finished.
  28. Do you wish the installer to initialize Anaconda3
  29. by running conda init? [yes|no]
  30. [no] >>>

Type yes if you want to initialize anaconda3 by running conda init.

Finally, take care of these instructions:

  1. ==> For changes to take effect, close and re-open your current shell. <==
  2.  
  3. If you'd prefer that conda's base environment not be activated on startup,
  4.    set the auto_activate_base parameter to false:
  5.  
  6. conda config --set auto_activate_base false
  7.  
  8. Thank you for installing Anaconda3!


7. Activate the Environment settings - activate the added environment settings in the “.bashrc” file by executing the following command:

  1. source ~/.bashrc


8. Verify the Anaconda installation - check the list of conda packages:


or check out the installed version of Anaconda:

  1. conda --version


9. Remove Anaconda from Ubuntu Linux - if you want to

In the terminal, you can write out the following command to remove Anaconda from your system:

  1. rm -rf ~/anaconda3

0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5211
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#8

Upgrade to the latest version of Ipython

  1. pip install ipython --upgrade


Currently the latest version of Ipython is 8.21.0
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
Post Reply
  • Similar Topics
    Replies
    Views
    Last post

Return to “Python Programming”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 0 guests