Giter Site home page Giter Site logo

pyenv-virtualenv's Introduction

pyenv-virtualenv

Build Status

pyenv-virtualenv is a pyenv plugin that provides features to manage virtualenvs and conda environments for Python on UNIX-like systems.

(NOTICE: If you are an existing user of virtualenvwrapper and you love it, pyenv-virtualenvwrapper may help you (additionally) to manage your virtualenvs.)

Installation

Installing as a pyenv plugin

This will install the latest development version of pyenv-virtualenv into the ~/.pyenv/plugins/pyenv-virtualenv directory.

Important note: If you installed pyenv into a non-standard directory, make sure that you clone this repo into the 'plugins' directory of wherever you installed into.

From inside that directory you can:

  • Check out a specific release tag.
  • Get the latest development release by running git pull to download the latest changes.
  1. Check out pyenv-virtualenv into plugin directory

    $ git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
    
  2. (OPTIONAL) Add pyenv virtualenv-init to your shell to enable auto-activation of virtualenv. This is entirely optional but pretty useful.

    $ echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
    

    Zsh note: Modify your ~/.zshenv file instead of ~/.bash_profile. Pyenv note: You may also need to add eval "$(pyenv init -)" to your profile if you haven't done so already.

  3. Restart your shell to enable pyenv-virtualenv

    $ exec "$SHELL"
    

Installing with Homebrew (for OS X users)

Mac OS X users can install pyenv-virtualenv with the Homebrew package manager. This will give you access to the pyenv-virtualenv command. If you have pyenv installed, you will also be able to use the pyenv virtualenv command.

This is the recommended method of installation if you installed pyenv with Homebrew.

$ brew install pyenv-virtualenv

Or, if you would like to install the latest development release:

$ brew install --HEAD pyenv-virtualenv

After installation, you'll still need to add

eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

to your profile (as stated in the caveats). You'll only ever have to do this once.

Usage

Using pyenv virtualenv with pyenv

To create a virtualenv for the Python version used with pyenv, run pyenv virtualenv, specifying the Python version you want and the name of the virtualenv directory. For example,

$ pyenv virtualenv 2.7.10 my-virtual-env-2.7.10

will create a virtualenv based on Python 2.7.10 under ~/.pyenv/versions in a folder called my-virtual-env-2.7.10.

Create virtualenv from current version

If there is only one argument given to pyenv virtualenv, the virtualenv will be created with the given name based on the current pyenv Python version.

$ pyenv version
3.4.3 (set by /home/yyuu/.pyenv/version)
$ pyenv virtualenv venv34

List existing virtualenvs

pyenv virtualenvs shows you the list of existing virtualenvs and conda environments.

$ pyenv shell venv27
$ pyenv virtualenvs
  miniconda3-3.9.1 (created from /home/yyuu/.pyenv/versions/miniconda3-3.9.1)
  miniconda3-3.9.1/envs/myenv (created from /home/yyuu/.pyenv/versions/miniconda3-3.9.1)
* venv27 (created from /home/yyuu/.pyenv/versions/2.7.10)
  venv34 (created from /home/yyuu/.pyenv/versions/3.4.3)

Activate virtualenv

Some external tools (e.g. jedi) might require you to activate the virtualenv and conda environments.

pyenv-virtualenv will automatically activate/deactivate the virtualenv if the eval "$(pyenv virtualenv-init -)" is properly configured in your shell.

You can also activate and deactivate a pyenv virtualenv manually:

pyenv activate <name>
pyenv deactivate

Delete existing virtualenv

Removing the directory in ~/.pyenv/versions will delete the virtualenv, or you can run:

pyenv uninstall my-virtual-env

virtualenv and pyvenv

There is a venv module available for CPython 3.3 and newer. It provides a command-line tool pyvenv which is the successor of virtualenv and distributed by default.

pyenv-virtualenv uses pyvenv if it is available and the virtualenv command is not available.

Anaconda and Miniconda

Because Anaconda and Miniconda may install standard commands (e.g. curl, openssl, sqlite3, etc.) into their prefix, we'd recommend you to install pyenv-which-ext.

You can manage conda environments by conda env as same manner as standard Anaconda/Miniconda installations. To use those environments, you can use pyenv activate and pyenv deactivate.

(root)$ pyenv version
miniconda3-3.9.1 (set by /home/yyuu/.pyenv/version)
(root)$ conda env list
# conda environments:
#
myenv                    /home/yyuu/.pyenv/versions/miniconda3-3.9.1/envs/myenv
root                  *  /home/yyuu/.pyenv/versions/miniconda3-3.9.1
(root)$ pyenv activate myenv
discarding /home/yyuu/.pyenv/versions/miniconda3-3.9.1/bin from PATH
prepending /home/yyuu/.pyenv/versions/miniconda3-3.9.1/envs/myenv/bin to PATH
(myenv)$ python --version
Python 3.4.3 :: Continuum Analytics, Inc.
(myenv)$ pyenv deactivate
discarding /home/yyuu/.pyenv/versions/miniconda3-3.9.1/envs/myenv/bin from PATH

You can use version like miniconda3-3.9.1/envs/myenv to specify conda environment as a version in pyenv.

(root)$ pyenv version
miniconda3-3.9.1 (set by /home/yyuu/.pyenv/version)
(root)$ pyenv shell miniconda3-3.9.1/envs/myenv
(myenv)$ which python
/home/yyuu/.pyenv/versions/miniconda3-3.9.1/envs/myenv/bin/python

Special environment variables

You can set certain environment variables to control pyenv-virtualenv.

  • PYENV_VIRTUALENV_CACHE_PATH, if set, specifies a directory to use for caching downloaded package files.
  • VIRTUALENV_VERSION, if set, forces pyenv-virtualenv to install the desired version of virtualenv. If virtualenv has not been installed, pyenv-virtualenv will try to install the given version of virtualenv.
  • GET_PIP, if set and pyvenv is preferred over virtualenv, use get_pip.py from the specified location.
  • GET_PIP_URL, if set and pyvenv is preferred over virtualenv, download get_pip.py from the specified URL.
  • PIP_VERSION, if set and pyvenv is preferred over virtualenv, install the specified version of pip.

Version History

See CHANGELOG.md.

License

(The MIT License)

  • Copyright (c) 2013 Yamashita, Yuu

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

pyenv-virtualenv's People

Contributors

yyuu avatar blueyed avatar s0undt3ch avatar wwwjfy avatar pygeek avatar fgimian avatar aristide-n avatar bcb avatar jawshooah avatar negamorgan avatar sfilipov avatar danse avatar keik avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.