Python Installation

Anh-Thi Dinh

Installation

pip

1python -m pip install --user --upgrade pip # install for current user only
2python -m pip install --upgrade pip # need to run cmder as administrator
1# INSTALL A PACKAGE
2pip install <package> # admin <-- SHOULDN'T!!!
3pip install --user <package> # current user only
4
1# LIST ALL INSTALLED PACKAGES
2pip freeze
1# REMOVE
2pip uninstall <package>
3pip uninstall --user <package
1# CHECK VERSION OF A PACKAGE
2pip show <package>
1# version <=
2pip3 install -U "pillow<7"
1# Install a package from a git repository
2pip install git+https://github.com/TimeSynth/TimeSynth.git
Install packages with requirement file,
1pip install -r requirements.txt

conda and environnement

Other packages to use: python3-venv, pyenv.
1# UPDATE CONDA
2conda --version # check version
3conda update -n base -c defaults conda
1# Create a new environment with python version 3.7
2conda create -n env_name python=3.10
1# activate this env
2source activate env_name
3# on macos
4conda activate env_name
1# Rename an env (conda >= 4.14)
2conda rename -n old_name -d new_name
1# remove an env
2conda remove --name env_name --all
1# list all env
2conda info --envs
3# or
4conda env list
1# EXPORT env list TO A ENV FILE
2conda env export -f <file>.yml
1# Update packages listed in an env file to current env,
2conda env update -n <env> -f /path/to/<file>.yml --prune

Troubleshooting

1# UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 975: ordinal not
2# solution: instead of
3pip3 install sesd
4# use
5LC_ALL=C.UTF-8 pip3 install sesd
1# conda: The following packages are not available from current channels:
2# Solution 1: One can use pip in this case (the same env with conda)
3# Solution 2:
4conda install -c anaconda <package>
1# The following required packages can not be built: * freetype (from matplotlib)
2# try to use conda to install matplotlib
3conda install matplotlib
4# it actually install the same thing as pip does on the same env
1# dtaidistance: C-library is not available
2pip install -vvv --upgrade --force-reinstall dtaidistance
1# zsh: command not found: conda
2# Make sure your installation folder is already
3# in the $PATH
4export PATH="/home/thi/miniconda3/bin:$PATH"