Praveen Chandrashekar

Centre for Applicable Mathematics, TIFR, Bangalore

[ People | News | Codes | Talks | Teaching | Publications | Calendar | Hiking | Contact ]

Python using Conda

I prefer to install Miniforge which is a community version of conda and uses conda-forge channel. It installs a minimal set of packages and then you can install whatever additional packages you need.

Install miniforge from github

Download the latest miniforge from here and the install from terminal

sh FILENAME.sh

Follow the instructions.

Install miniforge via brew

On mac, install using homebrew

brew install --cask miniforge
conda init zsh  # If you use zsh, this modifies your .zshrc file
conda activate

Now you can install the packages you need.

Install packages

conda update conda
conda update --all
conda install numpy scipy sympy matplotlib ipython 
conda install jupyterlab
conda install ipympl          # matplotlib widget for jupyter
conda install ipywidgets
conda install pyvista
conda install prettytable
conda install pandas
conda install pylint autopep8 # vscode wants these
conda install clingo          # needed by spack
conda install meshio          # to read gmsh grids
conda install fprettify       # tidy f90 code
conda install fortls          # needed to use vscode fortran
conda install lfortran        # jupyter fortran kernel
conda install imageio         # to read images from url
conda install vtk
conda install tensorflow      # if you need this
conda install tensorflow-probability
conda install scikit-learn
conda install deepxde

or together

conda update -y conda && conda update -y --all && \
conda install -y numpy scipy sympy matplotlib ipython \
                 jupyterlab ipympl ipywidgets \
                 pyvista prettytable pandas pylint autopep8 \
                 clingo meshio imageio vtk \
                 fprettify fortls lfortran \
                 tensorflow tensorflow-probability \
                 scikit-learn deepxde

I set PATH to point to conda directory

export PATH=/path/to/conda/bin:$PATH

Install matlab jupyter integration if needed

pip install jupyter-matlab-proxy

See installed packages

conda list

Upgrade all packages

conda upgrade --all

Periodically, delete older versions of packages

conda clean --all

Do not add env to prompt, we show it in window bar

conda config --set changeps1 False

Use Eigen with tensorflow

Install Miniconda and then

conda update conda
conda install nomkl  # use openblas instead of mkl
conda update --all
conda install tensorflow-eigen

Install Mayavi: using conda

Make sure you are using pip from conda

conda install mayavi
pip install PyQt5

To upgrade pip installed packages

pip install --upgrade PyQt5 PyQt5-sip

Install Mayavi: using pip

Conda may not have the latest mayavi, then use pip. Make sure you are using pip from Conda.

pip install mayavi
pip install PyQt5

To upgrade pip installed packages

pip install --upgrade mayavi PyQt5

To see packages installed with pip

conda list | grep pypi

pylab

pylab imports some commonly used modules like numpy. Define an alias

alias pylab="ipython --pylab --matplotlib --nosep --pprint"

Now you can use it like this

$ pylab
Python 3.9.9 | packaged by conda-forge | (main, Dec 20 2021, 02:41:07)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.0.0 -- An enhanced Interactive Python. Type '?' for help.
Using matplotlib backend: MacOSX
In [1]: x = linspace(0, pi, 100)
In [2]: y = sin(10 * x)
In [3]: plot(x, y)

Nbextensions

Install this to get ToC and other features in jupyter notebooks.

conda install  jupyter_contrib_nbextensions