Common Commands for pip & conda

pip

  1. Install script-house, version 0.0.2.

    1
    pip install script-house==0.0.2

    If you want to install the latest version by default, you can omit ==0.0.2.

    To install multiple dependencies in one line:

    1
    pip install script-house==0.0.2 pydantic==2.5.3 pymongo==4.6.1
  1. List all dependencies.

    1
    pip list
  2. List current dependencies in requirements.txt format.

    1
    pip freeze

    The result of pip freeze is a subset of pip list. pip list usually includes fundamental dependencies like pip, setuptools, and wheel.

    The purpose of pip freeze is to export project dependencies for others to use, while pip list is just for display.

    1
    pip freeze > requirements.txt
  3. Install all dependencies from requirements.txt.

    1
    pip install -r requirements.txt
  4. Uninstall a specific dependency.

    1
    pip uninstall script-house
  5. Uninstall multiple dependencies.

    1
    pip uninstall -r req.txt -y

    -y automatically confirms the deletion.

    How to uninstall all dependencies in the current environment?

    1
    2
    3
    pip freeze > req
    pip uninstall -r req -y
    del req

conda

  1. After conda is installed on Linux, you should run conda init first before using conda commands; On Windows, there is no such need.

  2. List all environments.

    1
    conda env list
  3. Create a new environment.

    1
    conda create -n <environment-name> python=3.8

    The basic command is conda create -n <environment-name>, but specifying the Python version is a common practice. Compared to venv, conda environments also install some basic OS-dependent dependencies.

  4. Activate an environment.

    1
    conda activate <environment-name>

    On Windows, you probably need to omit conda.

  5. Deactivate the environment.

    1
    conda deactivate
  6. Remove an environment.

    1
    conda remove -n <environment-name> --all
  7. View basic information.

    1
    conda info
  8. Install dependencies.

    1
    conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 -c pytorch -c conda-forge

    Similar to pip, it follows the format dependency==version; the -c parameter specifies the download source (channel) as default channels often fail.

  9. Create an environment from a configuration file (usually named environment.yml).

    1
    conda env create -f environment.yml

    Content of environment.yml:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    name: <environment-name>
    channels: # -c parameter, specifying download source
    - pytorch
    - conda-forge
    dependencies: # dependencies installed by conda
    - python=3.8
    - numpy
    - pandas
    - matplotlib
    - pip: # dependencies installed by pip
    - imageio

    It’s not recommended to create a new environment by this method, because channels often fail.

  10. Disable auto-activation of the base environment. If enabled, every new shell will automatically activate the base environment.

    1
    conda config --set auto_activate_base false