Skip to content

Instantly share code, notes, and snippets.

@pybokeh
Created February 22, 2016 20:00
Show Gist options
  • Select an option

  • Save pybokeh/d2fb9849009e727f03f9 to your computer and use it in GitHub Desktop.

Select an option

Save pybokeh/d2fb9849009e727f03f9 to your computer and use it in GitHub Desktop.
Conda HowTo
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"run_control": {
"read_only": false
}
},
"source": [
"# Using Conda To Manage Python Virtual Environments and Packages"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"After installing Anaconda/[Miniconda3](http://conda.pydata.org/miniconda.html) installer from Continuum Analytics, you would use the \"conda\", \"activate\", and \"deactivate\" commands to handle creation of virtual environments, activating/deactivating environments, and installing/uninstalling Python packages."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Some typical example usage:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Create a new Python 3.5 virtual environment called \"my_env\":**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"conda create -n my_env python=3.5"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**To activate the new virtual environment:**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"activate my_env"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**To install Python package:**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"conda install <package_name>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"** To update a Python package:**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"conda update <package_name>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"** To uninstall a Python package:**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"conda uninstall <pacakge_name>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**To view a list of installed packages in your environment:**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"conda list"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**To deactive your virtual environment:**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"deactivate # no need to enter environment name"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## You may still need to use pip!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you have a need for a Python package that is not available at Continuum Analytics, but available at [PyPi](https://pypi.python.org/pypi) repo, you can always use the pip command:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"pip install <package_name>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"** You can even install a GitHub repo package directly using pip:**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"pip install git+https://github.com/django-extensions/django-extensions.git"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Tried to install numpy on Windows, but failed because you don't have the proper C or Fortran compilers?<br><br>SOLUTION:** Download pre-compiled binaries! For pre-compiled Windows binaries, you can download them [here.](http://www.lfd.uci.edu/~gohlke/pythonlibs/)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Then install the .whl using pip:**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"pip install path_to_downloaded_whl_file"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Example:**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"pip install d:\\Downloads\\numpy-1.10.4+mkl-cp35-cp35m-win_amd64.whl"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.4"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment