Important: Under windows the default python interpreter must be listed before all other python versions in the Path Environment Variable.
Example for python version 3.10 under Windows:
> py -3.10Example for python version 3.10 under Windows:
> py -3.10 -m pip> pip install --upgrade pip setuptoolsPackage, dependency and environment management
For Windows:
Download miniconda and select add to path in the installer. After the installation run the following command and reopen the terminal:
> conda init powershell> conda info> conda update conda> conda env listFor environments that should be installed under the default location run:
> conda create -n <env name> python=<version>and for environments that should be installed under a specific location run:
> conda create --prefix <location> python=<version>For environments that should be installed under the default location run:
> conda env create -f <env file>and for environments that should be installed under a specific location run:
> conda env create --prefix <location> -f <env file>For environments installed under the default location run:
> conda activate <env name>> conda deactivate <env name>and for environments installed under a specific location run:
> conda activate <env location>> conda deactivate <env location>If you want to automatically activate an environment under Windows when opening the terminal add the above activation command to your PowerShell profile.
By default, conda prefers packages from a higher priority channel over any version from a lower priority channel. Therefore, you can now safely put channels at the bottom of your channel list to provide additional packages that are not in the default channels and still be confident that these channels will not override the core package set.
> conda config --append channels <channel name>Use the following command to search for packages in the default channels:
> conda search <package>or visit anaconda.org to also search for packages in other channels.
> conda install <package>> conda list> conda update <package>> conda update --allTo update micro versions (e.g. 3.10.0 => 3.10.1) run:
> conda update pythonTo update minor versions (e.g. 3.10.9 > 3.11.0) delete the environment with the python version you want to update and create a new environment from the env file which specifies the new python version.
> conda remove <package>> conda clean -allUnder Windows run:
> $envName = "<name>"; $output = ".\environment.yml"; `
conda env export --from-history > $output; `
(Get-Content $output) -Replace "^(name:).*$", "name: $envName" | Set-Content $output; `
(conda env export).Where({ $_ -match "- pip:" }, "SkipUntil" ) | Add-Content $output; `
(Get-Content $output) | Where-Object { $_ -notmatch "prefix" -and $_ -notmatch "autopep8" } | Set-Content $outputto get an basic env file that you can fine-tune by hand or do it completely manual by running:
Under Windows:
> conda env export > .\env1.yml; conda env export --from-history > .\env2.ymlUnder Linux:
> conda env export > ./env1.yml && conda env export --from-history > ./env2.ymland merging env1.yml and env2.yml to an environment.yml file.
Update the env file with the new packages and run
for environments installed under the default location:
> conda env update -n <env name> --file <env file> --pruneand for environments installed under a specific location:
> conda env update --prefix <env location> --file <env file> --prune--prune causes conda to remove any dependencies that are no longer required from the environment.
List environment history:
> conda list --revisionsRestore environment to a previous revision:
> conda install --revision=<rev number>For environments installed under the default location run:
> conda remove -n <env name> --alland for environments installed under a specific location run:
> conda remove --prefix <location> --allActivate the desired environment in the terminal and run the following command to open the desired folder in IntelliJ:
> idea <path>Opening the folder in this way ensures that all conda path variables are loaded correctly into IntelliJ.
For more commands take a look at the cheatsheet or the conda documentation.
Tool for creating isolated virtual python environments.
> python venv venvTo passthrough global installed packages to the virtual environment add the --system-site-packages flag and than if needed use pip install --ignore-installed to install newer versions of global installed packages in the virtual environmnent.
Example for python version 3.10 under Windows:
> py -3.10 -m venv venvUnder Windows run:
> .\venv\Scrips\Activate.ps1> deactivateLike pip freeze but lists only the packages that are not dependencies of installed packages.
> pip install pip-chill> pip-chill > requirements.txtTo suppress version numbers use the --no-version flag.