Common Commands for pip & conda
pip
-
Install
script-house
, version0.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
-
List all dependencies.
1
pip list
-
List current dependencies in
requirements.txt
format.1
pip freeze
The result of
pip freeze
is a subset ofpip list
.pip list
usually includes fundamental dependencies likepip
,setuptools
, andwheel
.The purpose of
pip freeze
is to export project dependencies for others to use, whilepip list
is just for display.1
pip freeze > requirements.txt
-
Install all dependencies from
requirements.txt
.1
pip install -r requirements.txt
-
Uninstall a specific dependency.
1
pip uninstall script-house
-
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
3pip freeze > req
pip uninstall -r req -y
del req
conda
-
After conda is installed on Linux, you should run
conda init
first before using conda commands; On Windows, there is no such need. -
List all environments.
1
conda env list
-
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. -
Activate an environment.
1
conda activate <environment-name>
On Windows, you probably need to omit
conda
. -
Deactivate the environment.
1
conda deactivate
-
Remove an environment.
1
conda remove -n <environment-name> --all
-
View basic information.
1
conda info
-
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. -
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
11name: <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
- imageioIt’s not recommended to create a new environment by this method, because channels often fail.
-
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