a capistrano recipe to deploy python apps with virtualenv.
Ruby Shell
Latest commit 8f25b3d Dec 19, 2013 Yamashita, Yuu Yamashita, Yuu Merge pull request #5 from mikepii/develop
do virtualenv:update after deploy:create_symlink



a capistrano recipe to deploy python apps with virtualenv.


Add this line to your application's Gemfile:

gem 'capistrano-virtualenv'

And then execute:

$ bundle

Or install it yourself as:

$ gem install capistrano-virtualenv


This recipe will create 2 kind of virtualenv during deploy task.

  • shared virtualenv
    • created in shared_path after deploy:setup
    • common libraries are installed here.
  • release virtualenv
    • created in release_path after deploy:finalize_update
    • per-release virtualenv that can be rolled back.

To deploy your application with virtualenv, add following in you config/deploy.rb.

# in "config/deploy.rb"
require 'capistrano-virtualenv'

Following options are available to manage your virtualenv.

  • :virtualenv_bootstrap_python - the python executable which will be used to craete virtualenv. by default "python".
  • :virtualenv_current_path - virtualenv path under :current_path.
  • :virtualenv_current_python - python path under :virtualenv_current_path.
  • :virtualenv_easy_install_options - options for easy_install. by defaul "--quiet".
  • :virtualenv_install_packages - apt packages dependencies for python.
  • :virtualenv_pip_options - options for pip. by default "--quiet".
  • :virtualenv_pip_install_options - options for pip install.
  • :virtualenv_release_path - virtualenv path under :release_path.
  • :virtualenv_release_python - python path under :virtualenv_release_path.
  • :virtualenv_requirements - the list of pip packages should be installed to virtualenv.
  • :virtualenv_requirements_file - the path to the file that describes library dependencies. by default "requirements.txt".
  • :virtualenv_script_url - the download URL of virtualenv.py.
  • :virtualenv_shared_path - virtualenv path under :shared_path.
  • :virtualenv_shared_python - python path under :virtualenv_shared_path
  • :virtualenv_use_system - controls whether virtualenv should be use system packages or not. false by default.


Upgrading base Python version

To upgrade base Python version of virtualenv, you must once remove existing shared virtualenv. Since the shared virtualenv is not referenced from release virtualenv after the creation, you can safely remove the shared virtualenv before and after the deployments.

$ cap virtualenv:destroy_shared # remove existing shared virtualenv
$ cap virtualenv:setup          # create virtualenv with new Python version
$ cap deploy


  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request