Python is a programming language that lets you work quickly and integrate systems more effectively.
This guide details on how to install both python
, the programming language, and pip
, Python's package manager.
-
Install
python
usingpacman
(oryay
):sudo pacman -S python
-
Install
pip
usingpacman
(oryay
):sudo pacman -S python-pip
Alternatively, we could also install
pip
usingpython
itself:python -m ensurepip --upgrade
This guide details on how use pip
to perform several operations including installing Python packages.
Note
Replace <package>
with the actual name of the package you wish to search, install, or update.
-
To install a Python package:
pip install <package>
-
To upgrade a Python package:
pip install --upgrade <package>
-
To uninstall a Python package:
pip uninstall <package>
-
To search for a Python package:
pip search <package>
-
To list all installed Python packages:
pip list
-
To freeze all installed Python packages into a
requirements.txt
file:pip freeze > requirements.txt
-
To install all Python packages listed in a
requirements.txt
file:pip install -r requirements.txt
Important
A portion of this guide assumes you are using the Fish shell. If you are using a different shell, make any required adjustments accordingly.
This guide details on how we could install, setup, and use Conda to create python
environments of various python
versions.
-
Install Miniconda:
mkdir -p ~/miniconda3 curl -Lo ~/miniconda3/miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3 rm -f ~/miniconda3/miniconda.sh
-
Add the Miniconda binary to
$PATH
temporarily (onfish
):fish_add_path ~/miniconda3/condabin
-
Configure Minicondawith the
fish
shell to have Miniconda available in our$PATH
permanently:conda init fish
Doing so should add this (with additional minor modification) to our
fish
config (i.e.~/.config/fish/config.fish
):if status is-interactive # >>> conda initialize >>> # !! Contents within this block are managed by 'conda init' !! if test -f ~/miniconda3/bin/conda eval ~/miniconda3/bin/conda "shell.fish" "hook" $argv | source end # <<< conda initialize <<< end
-
Update Conda:
conda update conda
-
The default Conda channels might be sufficient, but some packages might be missing (i.e.
python
<3.5).To fix this, add the
conda-forge
channel like so:conda config --append channels conda-forge
-
Check channels active/available to our Conda to ensure that
conda-forge
has been added:conda config --show channels
Sample output:
channels: - defaults - conda-forge
-
To create an environment named,
myenv
, running onpython
version3.5
:conda create --name myenv python=3.5
-
To activate the environment we created (i.e.
myenv
) and verify that it is running thepython
version we had set:conda activate myenv python --version
-
To exit/deactivate the environment we had activated:
conda deactivate
-
To delete an environment (i.e.
myenv
) permanently:conda env remove --name myenv
-
To list all available Conda environments on our system:
conda env list
Sample output:
# conda environments: # base * /home/myuser/miniconda3 myenv /home/myuser/miniconda3/envs/myenv
[!NOTE]
The*
indicates the active environment that we are currently in.