a pyenv plugin to manage virtualenv (a.k.a. python-virtualenv)

Overview

pyenv-virtualenv

Join the chat at https://gitter.im/yyuu/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 root)/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/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv
  2. (OPTIONAL) Add pyenv virtualenv-init to your shell to enable auto-activation of virtualenvs. This is entirely optional but pretty useful. See "Activate virtualenv" below.

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

    Fish shell note: Add this to your ~/.config/fish/config.fish

    status --is-interactive; and pyenv init - | source
    status --is-interactive; and pyenv virtualenv-init - | source

    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 macOS users)

macOS 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 root)/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 venv34
$ 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)
  2.7.10/envs/my-virtual-env-2.7.10 (created from /home/yyuu/.pyenv/versions/2.7.10)
  3.4.3/envs/venv34 (created from /home/yyuu/.pyenv/versions/3.4.3)
  my-virtual-env-2.7.10 (created from /home/yyuu/.pyenv/versions/2.7.10)
* venv34 (created from /home/yyuu/.pyenv/versions/3.4.3)

There are two entries for each virtualenv, and the shorter one is just a symlink.

Activate virtualenv

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

If eval "$(pyenv virtualenv-init -)" is configured in your shell, pyenv-virtualenv will automatically activate/deactivate virtualenvs on entering/leaving directories which contain a .python-version file that contains the name of a valid virtual environment as shown in the output of pyenv virtualenvs (e.g., venv34 or 3.4.3/envs/venv34 in example above) . .python-version files are used by pyenv to denote local Python versions and can be created and deleted with the pyenv local command.

You can also activate and deactivate a pyenv virtualenv manually:

pyenv activate <name>
pyenv deactivate

Delete existing virtualenv

Removing the directories in $(pyenv root)/versions and $(pyenv root)/versions/{version}/envs will delete the virtualenv, or you can run:

pyenv uninstall my-virtual-env

You can also delete existing virtualenvs by using virtualenv-delete command, e.g. you can run:

pyenv virtualenv-delete my-virtual-env

This will delete virtualenv called my-virtual-env.

virtualenv and venv

There is a venv module available for CPython 3.3 and newer. It provides an executable module venv which is the successor of virtualenv and distributed by default.

pyenv-virtualenv uses python -m venv if it is available and the virtualenv command is not available.

Anaconda and Miniconda

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

$ pyenv version
miniconda3-3.9.1 (set by /home/yyuu/.pyenv/version)
$ 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
$ pyenv activate miniconda3-3.9.1/envs/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
$ python --version
Python 3.4.3 :: Continuum Analytics, Inc.
$ pyenv deactivate
discarding /home/yyuu/.pyenv/versions/miniconda3-3.9.1/envs/myenv/bin from PATH

If conda is available, pyenv virtualenv will use it to create environment by conda create.

$ pyenv version
miniconda3-3.9.1 (set by /home/yyuu/.pyenv/version)
$ pyenv virtualenv myenv2
$ conda env list
# conda environments:
#
myenv                    /home/yyuu/.pyenv/versions/miniconda3-3.9.1/envs/myenv
myenv                    /home/yyuu/.pyenv/versions/miniconda3-3.9.1/envs/myenv2
root                  *  /home/yyuu/.pyenv/versions/miniconda3-3.9.1

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

$ pyenv version
miniconda3-3.9.1 (set by /home/yyuu/.pyenv/version)
$ pyenv shell miniconda3-3.9.1/envs/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 venv is preferred over virtualenv, use get_pip.py from the specified location.
  • GET_PIP_URL, if set and venv is preferred over virtualenv, download get_pip.py from the specified URL.
  • PIP_VERSION, if set and venv is preferred over virtualenv, install the specified version of pip.
  • PYENV_VIRTUALENV_VERBOSE_ACTIVATE, if set, shows some verbose outputs on activation and deactivation

Version History

See CHANGELOG.md.

License

(The MIT License)

  • Copyright (c) 2015 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.

Comments
  • Question regarding prompt changing

    Question regarding prompt changing

    Hi, I updated my Homebrew install and I'm now getting an info message displayed whenever I'm changing into directories that have a .python-version file in them (I'm guessing? I'm not entirely sure on what triggers the behaviour).

    It says: pyenv-virtualenv: prompt changing will be removed from future release. configureexport PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.` but it's not really clear to me from that message how the prompt will change in the future and how that variable is supposed to work, i.e. what its expected behaviour is.

    I added the var to my shell file just to try it out, and the resulting prompt is definitely not what I want, as it seems to get stuck in a mode where it always displays the currently activated virtualenv, regardless of where I am in my file system.

    Re: what's going to change: Will only the active/deactive messages disappear? Or both that and the prompt prefix that displays the virtualenv's name, like so (myvirtualenv) mymachine:~$?


    And a general question, not directly related to this issue: are you accepting PRs for improving documentation? Because I'd really like to add a bit of info to this repo's README that would've saved me lots of time trying to figure out a particular problem I had.

    opened by keikoro 37
  • zsh: command not found: pyenv

    zsh: command not found: pyenv

    My .zshenv contains

    export PYENV_ROOT="$HOME"/.pyenv
    export PATH="$PYENV_ROOT"/bin:"$PATH"
    if command -v pyenv 1>/dev/null 2>&1; then
      eval "$(pyenv init -)"
    fi
    

    which works fine, however, if I simply add eval "$(pyenv virtualenv-init -)" I keep receiving the message zsh: command not found: pyenv

    Pyenv and pyenv-virtualenv work perfectly fine and if I enter exec "$SHELL" the message goes away until I restart the terminal so I'm sure what the issue is.

    I'm running Arch Linux, Zsh 5.4.2-1, tmux 2.5-3, termite 12-2, and the master branch of both pyenv and pyenv-virtualenv pulled today.

    need-feedback 
    opened by rghamilton3 32
  • Can not access Anaconda/Miniconda environment as virtualenv

    Can not access Anaconda/Miniconda environment as virtualenv

    I'm showing you the steps I use to create a virtualenv based on miniconda. Finally you will see that the virtualenv was created but I can't access to it.

    1.0. Check my initial pyenv versions:

    $ pyenv versions
    * system (set by /home/oscar/.python-version)
    2.7.9
    3.5.1
    

    1.1 Install miniconda:

    $ pyenv install miniconda3-4.0.5
    
    $ pyenv versions
    * system (set by /home/oscar/.python-version)
      2.7.9
      3.5.1
      miniconda3-4.0.5
    

    1.2. Create the venvtest virtualenv based on miniconda:

    $ pyenv virtualenv miniconda3-4.0.5 venvtest
    
    $ pyenv versions
    * system (set by /home/oscar/.python-version)
      2.7.9
      3.5.1
      miniconda3-4.0.5
      miniconda3-4.0.5/envs/venvtest
      venvtest
    

    When I want to check if the virtualenv was created, It doesn't show it. So I can't no access to it :cry:

    $ pyenv virtualenvs
      miniconda3-4.0.5 (created from /home/oscar/.pyenv/versions/miniconda3-4.0.5)
    
    $ pyenv activate ... (autocompleting)
    --help            miniconda3-4.0.5  --unset 
    

    Please, I hope you can help me.

    conda unconfirmed 
    opened by oskargicast 30
  • Commands not available when using `--system-site-packages`

    Commands not available when using `--system-site-packages`

    I am trying to setup a virtualenv with --system-site-packages to use compiled/pre-built packages, and noticed that e.g. ipython fails to run with:

    % pyenv virtualenv --system-site-packages 3.4.2 paperwork3
    ...
    % ipython
    pyenv: ipython: command not found
    
    The `ipython' command exists in these Python versions:
    ...
    

    Trying to install it skips it, because it appears to be installed already.

    Could pyenv somehow handle this, especially after trying to (re-)install it?

    opened by blueyed 28
  • Post install package for every virtualenv created

    Post install package for every virtualenv created

    Is it possible to have a post install hook so that every time a new virtualenv is created a package is installed too?

    The use case is simple: i'd like - in the same way pip is installed - to have iPython installed automatically with every pyenv virtualenv created.

    opened by DanyC97 22
  • Cannot properly uninstall virtualenv

    Cannot properly uninstall virtualenv

    Hi,

    I have been messing around with this for a few minutes and I can't quite figure out what the issue is. So I made a virtualenv to test out pyechonest for my brother, and once I was done I went to delete the virtualenv. First I simply deleted the directory containing the virtualenv. I have done this in the past and it has worked fine.

    Now I get spammed with the following messages every time I execute any command in the terminal:

    pyenv: version `echonest2' is not installed
    pyenv: version `echonest2' not installed
    pyenv: version `echonest2' is not installed
    

    echonest2 is the name of the virtualenv that I created.

    I have also tried using pyenv uninstall echonest2 and that didn't seem to help either. The only way I can get these messages to stop showing up is to take the stuff related to pyenv out of my .bashrc. I have even tried completely uninstalling pyenv (by deleting the .pyenv) directory, and that still didn't solve it.

    Hopefully this makes sense.

    Thanks!

    P.S. I am running Arch Linux if that makes any difference.

    opened by matthieugrieger 22
  • pyenv-virtualenv initialisation failing.

    pyenv-virtualenv initialisation failing.

    When running $ eval "$(pyenv virtualenv-init -)", I always get this error message:

    Failed to deactivate virtualenv.
    
    Perhaps pyenv-virtualenv has not been loaded into your shell properly.
    Please restart current shell and try again.
    

    For some reason, I can still use it on the same shell I installed it in, but not any other shell. How do I load up pyenv-virtualenv properly? Note: I Installed it using Homebrew.

    I just realised I have issues with my virtualenv:

    $ python
    -bash: /Users/ncopty/.pyenv/versions/finprod/bin/python: No such file or directory
    
    $ ~/.virtualenvs/finprod/bin/python
    Python 2.7.2 (default, Jul  2 2014, 14:30:17) 
    [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.34.4)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    

    Which one is the correct one and why do I have two?

    opened by nayefc 19
  • Segmentation fault when using any pip command

    Segmentation fault when using any pip command

    while using any pip command I'm getting

    /home/neurlap/.pyenv/plugins/pyenv-pip-rehash/libexec/pip: line 20: 24753 Segmentation fault      (core dumped) "$PYENV_COMMAND_PATH" "$@"
    

    @native-api any help?

    need-feedback third-party 
    opened by abhinavsp0730 18
  • Major problems with current version of pyenv-virtualenv

    Major problems with current version of pyenv-virtualenv

    Hey there Yuu, hope you're well :smile:

    Since some of the latest commits, I've been having quite a few major problems with this extension I'm afraid.

    My test system is a fresh install of Ubuntu Server 12.04 with the regular bash shell.

    This output should explain the problems :smile:

    [email protected]:~$ pyenv versions
    * system (set by /home/fots/.pyenv/version)
      2.7.7
      3.4.1
    [email protected]:~$ python -V
    Python 2.7.3
    [email protected]:~$ pyenv global 2.7.7
    [email protected]:~$ python -V
    Python 2.7.7
    [email protected]:~$ pyenv virtualenv newproject
    New python executable in /home/fots/.pyenv/versions/newproject/bin/python
    Installing setuptools, pip...done.
    [email protected]:~$ pyenv activate newproject
    (newproject)[email protected]:~$ python -V
    Python 2.7.3
    (newproject)[email protected]:~$ pyenv deactivate
    (newproject)[email protected]:~$ unset PYENV_VERSION
    [email protected]:~$ pyenv virtualenv 2.7.7 newproject2
    New python executable in /home/fots/.pyenv/versions/newproject2/bin/python
    Installing setuptools, pip...done.
    [email protected]:~$ pyenv activate newproject2
    (newproject2)[email protected]:~$ python -V
    Python 2.7.3
    (newproject2)[email protected]:~$
    

    So in summary:

    • Creating a virtualenv always uses the system version of Python
    • Deactivating a virtualenv no longer correctly unsets the PYENV_VERSION environment variable

    Your help would be greatly appreciated Fotis

    opened by fgimian 17
  • Tox can't find python3.x executable in virtualenv

    Tox can't find python3.x executable in virtualenv

    After creating a virtualenv with:

    pyenv virtualenv 3.5.3 myenv
    

    I'm not able to run tox with this ini file:

    [tox]
    envlist = py35
    
    [testenv]
    commands =
        pytest {posargs: --pep8 --pylint}
    
    deps = .[test]
    

    The following error appears:

    ERROR: InvocationError: Failed to get version_info for python3.5: b"pyenv: python3.5: command not found\n\nThe `python3.5' command exists in these Python versions:\n  3.5.3\n\n"
    

    After checking my virtualenv it's clear that it doesn't contain a python3.5 symlink.

    (myenv) ➜  ~ ll /home/stefanga/.pyenv/versions/myenv/bin/      
    total 32K
    -rw-r--r-- 1 stefanga axusers 2.2K Mar  3 13:06 activate
    -rw-r--r-- 1 stefanga axusers 1.3K Mar  3 13:06 activate.csh
    -rw-r--r-- 1 stefanga axusers 2.4K Mar  3 13:06 activate.fish
    -rwxr-xr-x 1 stefanga axusers  276 Mar  3 13:06 easy_install
    -rwxr-xr-x 1 stefanga axusers  276 Mar  3 13:06 easy_install-3.5
    -rwxr-xr-x 1 stefanga axusers  248 Mar  3 13:06 pip
    -rwxr-xr-x 1 stefanga axusers  248 Mar  3 13:06 pip3
    -rwxr-xr-x 1 stefanga axusers  248 Mar  3 13:06 pip3.5
    lrwxrwxrwx 1 stefanga axusers   47 Mar  3 13:06 python -> /home/stefanga/.pyenv/versions/3.5.3/bin/python
    lrwxrwxrwx 1 stefanga axusers    6 Mar  3 13:06 python3 -> python
    

    After creating the python3.5 -> python symlink manually tox executed without any errors.

    Shouldn't all executables (python, pythonx and python x.y) be available in the virtualenv?


    Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

    opened by gangefors 16
  • How does the auto activation/ deactivation works?

    How does the auto activation/ deactivation works?

    I'm running Mac 10.9.5 and i did the installation as below:

    brew install pyenv
    eval "$(pyenv init -)" >> ~/.bashrc
    brew install pyenv-virtualenv
    eval "$(pyenv virtualenv-init -)" >> ~/.bashrc
    

    The installation home is all under

    pyenv versions
    * system (set by /usr/local/opt/pyenv/version)
      3.4.2
      ra1
    
    [[email protected] in ~]# ll /usr/local/opt/pyenv*
    lrwxr-xr-x  1 dani  admin    24B Oct 22 16:27 /usr/local/opt/pyenv -> ../Cellar/pyenv/20141012
    lrwxr-xr-x  1 dani  admin    35B Oct 22 16:38 /usr/local/opt/pyenv-virtualenv -> ../Cellar/pyenv-virtualenv/20141012
    
    

    I read the other issues - #47 , #48, #32 , #33 and i've followed the same steps as in #32 (i get this are the manual steps)

    [[email protected] in ~]# pyenv versions
    * system (set by /usr/local/opt/pyenv/version)
      3.4.2
      ra1
    [[email protected] in ~]# python -V
    Python 2.7.6
    [[email protected] in ~]# echo PYENV_ACTIVATED
    PYENV_ACTIVATED
    [[email protected] in ~]# echo $PYENV_ACTIVATED
    
    [[email protected] in ~]# echo $PYENV_DEACTIVATED
    
    [[email protected] in ~]# echo $PYENV_VIRTUALENV_INIT
    1
    [[email protected] in ~]# pyenv activate ra1
    (ra1) [[email protected] in ~]# python -V
    Python 3.4.2
    (ra1) [[email protected] in ~]# echo $PYENV_ACTIVATED
    
    (ra1) [[email protected] in ~]# echo $PYENV_DEACTIVATED
    
    (ra1) [[email protected] in ~]# echo $PYENV_VERSION
    ra1
    (ra1) [[email protected] in ~]# pyenv deactivate
    [[email protected] in ~]# echo $PYENV_VERSION
    ra1
    [[email protected] in ~]# echo $PYENV_DEACTIVATED
    
    [[email protected] in ~]# echo $PYENV_ACTIVATED
    
    [[email protected] in ~]# pyenv version
    ra1 (set by PYENV_VERSION environment variable)
    [[email protected] in ~]# pyenv versions
      system
      3.4.2
    * ra1 (set by PYENV_VERSION environment variable)
    [[email protected] in ~]#
    
    

    BUT because the above behavior, when i'm trying to uninstall the virtual env i get this error

    [[email protected] in ~]# pyenv uninstall ra1
    pyenv: remove /usr/local/opt/pyenv/versions/ra1? y
    [[email protected] in ~]# pyenv versions
    pyenv: version `ra1' is not installed
      system
      3.4.2
    

    In #47 you mentioned,

    As you mentioned, PYENV_DEACTIVATED should not persist after automatically triggered deactivation. I'll try to fix it in #47.

    hence my question: _what is the working flow for the auto activation/ deactivation? Do i need to be inside the PYENV_ROOT in order for auto activation to kick in?_

    In addition to this issue, according to the README file, the pyenv-virtualenv should be registered as a plugin inside pyenv, is this a bug in the brew formula's installation?

    [[email protected] in ~]# ll /usr/local/opt/pyenv/plugins/
    total 8
    lrwxr-xr-x  1 dani  admin    61B Oct 22 16:27 python-build -> /usr/local/Cellar/pyenv/20141012/default-plugins/python-build
    
    opened by DanyC97 16
  • `pyenv virtualenvs` failure on macOS Big Sur

    `pyenv virtualenvs` failure on macOS Big Sur

    Too many issues will kill our team's development velocity, drastically. Make sure you have checked all steps below.

    Prerequisite

    • [x] Make sure your problem is not listed in the common build problems.
    • [ x Make sure no duplicated issue has already been reported in the pyenv-virtualenv issues. You should look in closed issues, too.
    • [x] Make sure you are not asking us to help solving your specific issue.
      • GitHub issues is opened mainly for development purposes. If you want to ask someone to help solving your problem, go to some community site like Gitter, StackOverflow, etc.
    • [x] Make sure your problem is not derived from packaging (e.g. Homebrew).
      • Please refer to the package documentation for the installation issues, etc.
    • [x] Make sure your problem is not derived from other plugins.
      • This repository is maintaining the pyenv-virtualenv plugin only. Please refrain from reporting issues of other plugins here.

    Description

    • [x] Platform information (e.g. Ubuntu Linux 20.04): macOS 11 Big Sur
    • [x] OS architecture (e.g. amd64): arm64 & x86_64
    • [x] pyenv version: 2.3.9
    • [x] pyenv-virtualenv version: 1.2.0
    • [x] Python version: 3.11.1
     "$(pyenv init -)" && pyenv virtualenvs
      /usr/bin/readlink: illegal option -- f
    

    Hello. macOS Big Sur does not support readlink -f. Recent changes in https://github.com/pyenv/pyenv-virtualenv/commit/c4de2555b7343c95a3380dece3098eaf3baa4e73 have fixed build errors for newer versions of macOS, but Big Sur cannot handle this. Is Big Sur still a supporterd OS?

    Relevant Homebrew CI run with the failures: https://github.com/Homebrew/homebrew-core/actions/runs/3844517040/jobs/6561365032

    opened by p-linnane 0
  • Activate virtualenv: Example

    Activate virtualenv: Example

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

    If eval "$(pyenv virtualenv-init -)" is configured in your shell, pyenv-virtualenv will automatically activate/deactivate virtualenvs on entering/leaving directories which contain a .python-version file that contains the name of a valid virtual environment as shown in the output of pyenv virtualenvs (e.g., venv34 or 3.4.3/envs/venv34 in example above) . .python-version files are used by pyenv to denote local Python versions and can be created and deleted with the pyenv local command.

    • For example::The virtual space name is my-virtual-env-2.7.10,Create a file named .python-versionin the virtual space folder my-virtual-env-2.7.10, and add the text of the micro virtual space name my-virtual-env-2.7.10

    echo "my-virtual-env-2.7.10" >> $HOME/.pyenv/versions/2.7.10/envs/my-virtual-env-2.7.10/.python-version

    You can also activate and deactivate a pyenv virtualenv manually:

    pyenv activate <name>
    pyenv deactivate
    
    opened by pgy866 0
  • [Feature Request] Migrate virtualenv to newer Python version

    [Feature Request] Migrate virtualenv to newer Python version

    When a new Python version is released, I want to be able to migrate my virtualenv to the newer version without the need of reinstalling all the dependencies.

    I want to be able to move it back to the previous/older versions too when needed

    opened by joselsegura 0
  • `pyenv-virtualenv` not auto-resolve version

    `pyenv-virtualenv` not auto-resolve version

    pyenv-virtualenv not auto-resolve python version like pyenv can (for example, now, pyenv install 3.10 will install current latest 3.10.8) https://github.com/pyenv/pyenv#prefix-auto-resolution

    Command pyenv virtualenv 3.10 venv will create folder $PYENV_ROOT/versions/3.10/envs/venv instead of expected $PYENV_ROOT/versions/3.10.8/envs/venv

    This also will break pyenv auto-resolve option, because even after delete virtual environment folder, $PYENV_ROOT/versions/3.10 will exist Related pyenv issue: https://github.com/pyenv/pyenv/issues/2533

    NB: Also, I've faced fork-bomb problem somehow with this, when delete one of environments, caused by pyenv sh-activate in eval "$(pyenv virtualenv-init -)", but I didn't investigate this deeply, just completely remove $PYENV_ROOT and recreate it.

    Prerequisite

    • [x] Make sure your problem is not listed in the common build problems.
    • [x] Make sure no duplicated issue has already been reported in the pyenv-virtualenv issues. You should look in closed issues, too.
    • [x] Make sure you are not asking us to help solving your specific issue.
      • GitHub issues is opened mainly for development purposes. If you want to ask someone to help solving your problem, go to some community site like Gitter, StackOverflow, etc.
    • [x] Make sure your problem is not derived from packaging (e.g. Homebrew).
      • Please refer to the package documentation for the installation issues, etc.
    • [x] Make sure your problem is not derived from other plugins.
      • This repository is maintaining the pyenv-virtualenv plugin only. Please refrain from reporting issues of other plugins here.

    Description

    • Platform information: openSUSE Tumbleweed
    • OS architecture (e.g. amd64): amd64
    • pyenv version: 2.3.6
    • pyenv-virtualenv version: 1.1.5
    • Python version: 2.7.18, 3.10.8
    • virtualenv version (if installed): none
    opened by psydvl 0
  • Pyenv not deactivating

    Pyenv not deactivating

    Pyenv is not deactivating from virtual environment: Python 3.10.6

    Description

    • [ ] Platform information (e.g. Ubuntu Linux 20.04): macOS Monterey
    • [ ] OS architecture (e.g. amd64): M1
    • [ ] pyenv version: 2.3.5
    • [ ] pyenv-virtualenv version: 1.1.5
    • [ ] Python version: 3.10.6
    • [ ] virtualenv version (if installed):
    • [ ] Please attach the debug log of a faulty Pyenv invocation as a gist
    (pysyft_0.7.0) [email protected] Infrastructure_as_code % 
    pyenv deactivate
    (pysyft_0.7.0) mac@ user1-MacBook-Pro Infrastructure_as_code % 
    (pysyft_0.7.0) mac@ user1-MacBook-Pro Infrastructure_as_code % 
    

    Looked into similar issues before raising current issue. Hope to get some help!

    opened by Sukanya-rs 6
  • venv with system-site-packages enabled invokes console scripts in the parent version context

    venv with system-site-packages enabled invokes console scripts in the parent version context

    When a pyenv virtualenv is created with system-site-packages enabled, console scripts installed in the parent pyenv version are invoked using the parent's environment, not the current virtual environment, and cannot load packages installed in the virtualenv.

    Reproduction:

    Create a venv from a parent version that has packages with console scripts. Here, package pyright has a console script.

    > pyenv virtualenv --system-site-packages 3.10.5 foo
    > pyenv shell foo
    foo > pyenv which pyright
    /Users/tmiller/.pyenv/versions/3.10.5/bin/pyright
    

    We pip install a package into the venv.

    foo > pip install kopf
    Looking in indexes: https://artifacts.mitre.org/artifactory/api/pypi/python/simple
    Collecting kopf
      Downloading https://artifacts.mitre.org/artifactory/api/pypi/python/packages/packages/80/eb/e82f3e249db2ecd06aeb42eb4209ea295a00a98b9277bff13901e99ddeda/kopf-1.35.6-py3-none-any.whl (205 kB)
    [...]
    

    When invoked, pyright parses code and imports, but can't find the package in the venv.

    foo > pyright ~/projects/foo
    No configuration file found.
    No pyproject.toml file found.
    stubPath /Users/tmiller/typings is not a valid directory.
    Assuming Python platform Darwin
    Searching for source files
    Found 1 source file
    pyright 1.1.269
    /Users/tmiller/projects/foo/bar.py
      /Users/tmiller/projects/foo/bar.py:3:8 - error: Import "kopf" could not be resolved (reportMissingImports)
    1 error, 0 warnings, 0 informations
    Completed in 0.596sec
    

    When the console script is invoked as a module entry point, the import is resolved because python is executed in the venv.

    foo > python -m pyright ~/projects/foo/
    No configuration file found.
    No pyproject.toml file found.
    stubPath /Users/tmiller/typings is not a valid directory.
    Assuming Python platform Darwin
    Searching for source files
    Found 1 source file
    pyright 1.1.269
    /Users/tmiller/projects/foo/bar.py
      /Users/tmiller/projects/foo/bar.py:6:2 - error: Argument of type "(namespace: Unknown, name: Unknown, resource: Unknown, **_: Unknown) -> dict[tuple[Unknown, Unknown], Unknown]" cannot be assigned to parameter of type "IndexingFn"
        Type "(namespace: Unknown, name: Unknown, resource: Unknown, **_: Unknown) -> dict[tuple[Unknown, Unknown], Unknown]" cannot be assigned to type "IndexingFn"
          Function accepts too many positional parameters; expected 3 but received 15 (reportGeneralTypeIssues)
    1 error, 0 warnings, 0 informations
    Completed in 0.82sec
    

    Prerequisite

    There are a couple of close issues, but nothing really seemed to match.

    • [x] Make sure you are not asking us to help solving your specific issue.
    • [x] Make sure your problem is not derived from packaging (e.g. Homebrew).
    • [x] Make sure your problem is not derived from other plugins.

    Description

    • [x] Platform information (e.g. Ubuntu Linux 20.04):
    • [x] OS architecture (e.g. amd64):
    Darwin yadda 20.6.0 Darwin Kernel Version 20.6.0: Tue Jun 21 20:50:28 PDT 2022; root:xnu-7195.141.32~1/RELEASE_X86_64 x86_64
    
    • [x] pyenv version:
    pyenv 2.3.1-20-g572a8bcf
    
    • [x] pyenv-virtualenv version:
    pyenv-virtualenv 1.1.5 (python -m venv)
    
    • [x] Python version:

    All.

    • [x] virtualenv version (if installed):

    N/A

    • [x] Please attach the debug log of a faulty Pyenv invocation as a gist

    https://gist.github.com/Cerebus/bf0a32edd99d6d8c00a29401628771f8

    opened by Cerebus 4
Releases(v1.2.0)
  • v1.2.0(Jan 5, 2023)

    What's Changed

    • ~/.*rc should be modified instead of ~/.*profile by @native-api in https://github.com/pyenv/pyenv-virtualenv/pull/384
    • Fixes #394 - update pyenv virtualenvs to list virtualenvs start with dot prefixes by @Gauravtalreja1 in https://github.com/pyenv/pyenv-virtualenv/pull/395
    • Fix installation steps to allow for Pyenv 2 by @native-api in https://github.com/pyenv/pyenv-virtualenv/pull/388
    • Fix get-pip.py URLs for older versions of Python by @jivanf in https://github.com/pyenv/pyenv-virtualenv/pull/403
    • Add (y/N) prompt help text by @sh-cho in https://github.com/pyenv/pyenv-virtualenv/pull/404
    • perf(sh-activate): avoid a pyenv-version-name call by @scop in https://github.com/pyenv/pyenv-virtualenv/pull/380
    • Fix unbound variable errors when running pyenv activate with set -u Use default empty value. This fixes #422. by @ackalker in https://github.com/pyenv/pyenv-virtualenv/pull/423
    • Fix another unbound variable error by @ackalker in https://github.com/pyenv/pyenv-virtualenv/pull/424
    • Update get-pip.py URLs in pyenv-virtualenv by @mcdonnnj in https://github.com/pyenv/pyenv-virtualenv/pull/426
    • Deduplicate shims in $PATH for the fish shell during initialization by @ericvw in https://github.com/pyenv/pyenv-virtualenv/pull/430
    • Upgrade uninstall hook after pyenv/pyenv#2432 by @laggardkernel in https://github.com/pyenv/pyenv-virtualenv/pull/438
    • Stop delete force failing when virtualenv does not exist by @eganjs in https://github.com/pyenv/pyenv-virtualenv/pull/330
    • fix: relative path to pyenv-realpath.dylib by @scop in https://github.com/pyenv/pyenv-virtualenv/pull/378
    • Spelling fixes by @scop in https://github.com/pyenv/pyenv-virtualenv/pull/352
    • Clone bats with --depth=1, gitignore it by @scop in https://github.com/pyenv/pyenv-virtualenv/pull/351
    • set -u fixes by @scop in https://github.com/pyenv/pyenv-virtualenv/pull/350
    • Set up Github Actions CI by @native-api in https://github.com/pyenv/pyenv-virtualenv/pull/440
    • Enhance documentation about options for pyenv virtualenv by @pylipp in https://github.com/pyenv/pyenv-virtualenv/pull/425
    • Return control to pyenv-uninstall in uninstall/envs.bash by @aiguofer in https://github.com/pyenv/pyenv-virtualenv/pull/321
    • Use realpath of scripts to determine relative locations by @andrew-christianson in https://github.com/pyenv/pyenv-virtualenv/pull/308
    • Shell detect improvements by @scop in https://github.com/pyenv/pyenv-virtualenv/pull/377

    New Contributors

    • @native-api made their first contribution in https://github.com/pyenv/pyenv-virtualenv/pull/384
    • @Gauravtalreja1 made their first contribution in https://github.com/pyenv/pyenv-virtualenv/pull/395
    • @jivanf made their first contribution in https://github.com/pyenv/pyenv-virtualenv/pull/403
    • @sh-cho made their first contribution in https://github.com/pyenv/pyenv-virtualenv/pull/404
    • @ackalker made their first contribution in https://github.com/pyenv/pyenv-virtualenv/pull/423
    • @mcdonnnj made their first contribution in https://github.com/pyenv/pyenv-virtualenv/pull/426
    • @ericvw made their first contribution in https://github.com/pyenv/pyenv-virtualenv/pull/430
    • @laggardkernel made their first contribution in https://github.com/pyenv/pyenv-virtualenv/pull/438
    • @eganjs made their first contribution in https://github.com/pyenv/pyenv-virtualenv/pull/330
    • @pylipp made their first contribution in https://github.com/pyenv/pyenv-virtualenv/pull/425
    • @aiguofer made their first contribution in https://github.com/pyenv/pyenv-virtualenv/pull/321
    • @andrew-christianson made their first contribution in https://github.com/pyenv/pyenv-virtualenv/pull/308

    Full Changelog: https://github.com/pyenv/pyenv-virtualenv/compare/v1.1.5...v1.2.0

    Source code(tar.gz)
    Source code(zip)
  • v1.1.5(Feb 14, 2019)

  • v1.1.4(Feb 8, 2019)

  • v1.1.3(May 24, 2018)

  • v1.1.1(Sep 20, 2017)

    • Set CONDA_PREFIX to make is useable in conda activate/deactivate scripts (#224)
    • Generate pydoc executable after creating new virtualenv (#197, #230)
    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Jul 3, 2017)

  • v1.0.0(Jul 3, 2017)

Owner
pyenv
pyenv
pyenv
Virtual Python Environment builder

virtualenv A tool for creating isolated virtual python environments. Installation Documentation Changelog Issues PyPI Github Code of Conduct Everyone

Python Packaging Authority 4.3k Dec 30, 2022
A simple but powerful Python packer to run any project with any virtualenv dependencies anywhwere.

PyEmpaq A simple but powerful Python packer to run any project with any virtualenv dependencies anywhwere. With PyEmpaq you can convert any Python pro

Facundo Batista 23 Sep 22, 2022
A pythonic interface to high-throughput virtual screening software

pyscreener A pythonic interface to high-throughput virtual screening software Overview This repository contains the source of pyscreener, both a libra

56 Dec 15, 2022
Define requirements inside your python code and scriptenv makes them ready to import.

scriptenv Define requirements inside your python code and scriptenv makes them ready to import. Getting Started Install scriptenv $ pip install script

Stefan Hoelzl 6 Nov 04, 2022
An experimental technique for efficiently exploring neural architectures.

SMASH: One-Shot Model Architecture Search through HyperNetworks An experimental technique for efficiently exploring neural architectures. This reposit

Andy Brock 478 Aug 04, 2022
Run a command in the named virtualenv.

Vex Run a command in the named virtualenv. vex is an alternative to virtualenv's source wherever/bin/activate and deactivate, and virtualenvwrapper's

Sasha Hart 374 Dec 21, 2022
The GNS3 server manages emulators such as Dynamips, VirtualBox or Qemu/KVM

GNS3-server This is the GNS3 server repository. The GNS3 server manages emulators such as Dynamips, VirtualBox or Qemu/KVM. Clients like the GNS3 GUI

GNS3 644 Dec 30, 2022
a pyenv plugin to manage virtualenv (a.k.a. python-virtualenv)

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

pyenv 5.3k Jan 08, 2023
PyDynamica is a freely available agent-based economy simulation

PyDynamica PyDynamica is a pure python implementation of Sociodynamica, a virtual environment to simulate a simple economy with minimal dependencies.

4 Sep 10, 2022
to-requirements.txt allows to automatically add and delete modules to requirements.txt installing them using pip.

to-requirements.txt | Automatically update requirements.txt to-requirements.txt allows to automatically add and delete modules to requirements.txt ins

Ilya 16 Dec 29, 2022
macOS development environment setup: Setting up a new developer machine can be an ad-hoc, manual, and time-consuming process.

dev-setup Motivation Setting up a new developer machine can be an ad-hoc, manual, and time-consuming process. dev-setup aims to simplify the process w

Donne Martin 5.9k Jan 02, 2023
A fast and easy python virtual environment creator for linux with some pre-installed libraries.

python-venv-creator A fast and easy python virtual environment created for linux with some optional pre-installed libraries. Dependencies: The followi

2 Apr 19, 2022
Ready-to-run Docker images containing Jupyter applications

Jupyter Docker Stacks are a set of ready-to-run Docker images containing Jupyter applications and interactive computing tools.

Project Jupyter 7k Jan 03, 2023
Manage python virtual environments on the working notebook server

notebook-environments Manage python virtual environments on the working notebook server. Installation It is recommended to use this package together w

Vladislav Punko 44 Nov 02, 2022
A PipEnv Environment Switcher

Pipes Pipenv Environment Switcher ⚡ Overview Pipes is a Pipenv companion CLI tool that provides a quick way to jump between your pipenv powered projec

Gui Talarico 131 Sep 04, 2022
Simple Python version management

Simple Python Version Management: pyenv pyenv lets you easily switch between multiple versions of Python. It's simple, unobtrusive, and follows the UN

pyenv 30.1k Jan 04, 2023
This tool is used to install `pyenv` and friends.

pyenv installer This tool installs pyenv and friends. It is inspired by rbenv-installer. Prerequisites In general, compiling your own Python interpret

pyenv 3.5k Jan 03, 2023
Python Development Workflow for Humans.

Pipenv: Python Development Workflow for Humans [ ~ Dependency Scanning by PyUp.io ~ ] Pipenv is a tool that aims to bring the best of all packaging wo

Python Packaging Authority 23.5k Jan 01, 2023
Python virtualenvs in Debian packages

dh-virtualenv Contents Overview Presentations, Blogs & Other Resources Using dh-virtualenv How does it work? Running tests Building the package in a D

Spotify 1.5k Jan 02, 2023
Fish shell tool for managing Python virtual environments

VirtualFish VirtualFish is a Python virtual environment manager for the Fish shell. You can get started by reading the documentation. (It’s quite shor

Justin Mayer 968 Dec 24, 2022