python conda - ghdrako/doc_snipets GitHub Wiki

To have a distinct Python interpreter for your project, you can use conda to manage the virtual environments.

conda create -n taskier-env python=3.10.4 streamlit=1.10.0  
conda create name myenv python=3.10.9
conda activate myenv
conda install tensorflow
conda install scikit-learn
conda install matplotlib
conda install seaborn
conda install pandas
conda install xgboost
conda install jupyter
jupyter notebook
conda list # check the list of all packages installed in the current environment
conda deactivate
conda env list #  list of all environments 

Conda is a package manager application that quickly installs, runs, and updates packages and their dependencies. Conda is also an environment manager application. A conda environment is a directory that contains a specific collection of conda packages that you have installed. For example, you may have one environment with NumPy 1.7 and its dependencies, and another environment with NumPy 1.6 for legacy testing.

conda --version
conda update conda
conda update python        # upgrade python the same branch 3.4.2 -> 3.4.3
conda install python=3.6   # upgrade Python to another branch such as 3.6 by installing that version of Python
conda create -n py27 python=2.7 anaconda #create a Python 2.7 environment
conda create -n py36 python=3.6 anaconda #make the new environment for Python 3.6

Managing environments

Create a separate environment

conda create --name snowflakes biopython           # /envs/snowflakes that contains the program Biopython. 

This environment will use the same version of Python that you are currently using, because you did not specify a version.

conda create --name bunnies python=3 astroid babel # second new environment named /envs/bunnies with Python 3 and Astroid and Babel installed.
conda create -n myenv python

Change environments (activate/deactivate)

  • Linux, OS X: source activate snowflakes / source deactivate
  • Windows: activate snowflakes / deactivate

List all environments

conda info --envs # list of environments
conda env list    # list of all environments, with the current environment highlighted with an ‘*’ character.

Clone an environment

conda create --name flowers --clone snowflakes # clone snowflakes to create an exact copy named flowers

Remove an environment

conda remove --name flowers --all

Share an environment

Export the environment file

conda env export > environment.yml  # Export your active environment to the file
conda env create -f environment.yml # Recreate the environment from file
Example1 file.yml:
name: stats
dependencies:
  - numpy
  - pandas

Example2 file.yml:
name: stats2
channels:
  - javascript
dependencies:
  - python=3.4   # or 2.7
  - bokeh=0.9.2
  - numpy=1.9.*
  - nodejs=0.10.*
  - flask
  - pip:
    - Flask-Testing

Build identical conda environments

conda list --explicit > spec-file.txt
conda create --name MyEnvironment --file spec-file.txt  # create an identical environment 
conda install --name MyEnvironment --file spec-file.txt # adds these packages to an existing environment.Must be the same platform in ex # platform: osx-64
Example spec-file.txt
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: osx-64
@EXPLICIT
https://repo.continuum.io/pkgs/free/osx-64/mkl-11.3.3-0.tar.bz2
https://repo.continuum.io/pkgs/free/osx-64/numpy-1.11.1-py35_0.tar.bz2
https://repo.continuum.io/pkgs/free/osx-64/openssl-1.0.2h-1.tar.bz2
conda list                # list all of your packages in the active environment
conda list -n snowflakes  # list all of your packages installed into a non-active environment
conda search beautiful-soup
conda install --name bunnies beautiful-soup # install a package such as “Beautiful Soup” into the current environment

conda install -c pandas bottleneck # Conda install the Bottleneck package from the Pandas channel on Anaconda.org.

conda update biopython

conda remove --name bunnies iopro # remove it from the bunnies environment 


conda config --add channels new_channel       # add channel on top of the list highest priority
conda config --append channels new_channel    # add chanell at the bottom of the channel list, making it the lowest priority.
⚠️ **GitHub.com Fallback** ⚠️