Skip to content

bug: pyenv rehash introduces bug with virtualenvwrapper #287

Closed

Description

@filipporemonato

Describe the bug
I installed pyenv-win, and subsequently installed a new Python with version 3.7. In Python 3.7, I pip-installed virtualenvwrapper-win. Following the instructions on virtualenvwrapper, I tried running a command like mkvirtualenv, which returned "mkvirtualenv is not a recognized command". Then I remembered I had to rehash pyenv after the install, and so did pyenv rehahs. Now running mkvirtualenv gives "Scripts is not a recognized command".
I also tried uninstalling and reinstalling virtualenvwrapper, with rehash right after both uninstall and reinstall, but the same error occurrs (see screenshot).

To Reproduce
Steps to reproduce the behavior:

  1. Install pyenv-win and new Python version, switch to that Python version with pyenv shell 3.7.6. Confirm correct Python version is active.
  2. Install virtualenvwrapper-win via pip install virtualenvwrapper-win
  3. Rehahs pyenv-win with pyenv rehahs
  4. See error

Expected behavior
To be able to run mkvirtualenv <env> or other commands related to virtualenvwrapper

Screenshots
image

Desktop (please complete the following information):

  • OS: Windows 10
  • Tools used: Command Prompt (cmd)
  • Version: Pyenv-win version 2.64.8

Additional context
I also tried finding the file "virtualenvwrapper.sh", fillowing the instructions on virtualenvwrapper, but that file is nowhere to be found, I only find a "virtualenvwrapper.bat" inside [...]\.pyenv\pyenv-win\versions\3.7.6\Scripts.

Activity

  1. thebjorn commented on Jul 19, 2021

    @thebjorn

    Maybe related..? davidmarble/virtualenvwrapper-win#112

    virtualenvwrapper-win is a windows implementation of virtualenvwrapper and therefore does not use the virtualenvwrapper.sh file, instead it installs its implementation (a number of .bat files) in the Scripts directory of the system python, e.g.

    (dev35) go|c:\Program Files (x86)\Python35-32\Scripts> dir *.bat
     Volume in drive C is OS
     Volume Serial Number is 4C4D-147C
    
     Directory of c:\Program Files (x86)\Python35-32\Scripts
    
    11/07/2018  12:52 AM             1,805 add2virtualenv.bat
    08/05/2017  11:51 PM                83 cd-.bat
    11/07/2018  12:52 AM               823 cdproject.bat
    08/05/2017  11:51 PM               368 cdsitepackages.bat
    08/05/2017  11:51 PM               350 cdvirtualenv.bat
    11/07/2018  12:52 AM               495 folder_delete.bat
    08/05/2017  11:51 PM               997 lssitepackages.bat
    08/05/2017  11:51 PM               267 lsvirtualenv.bat
    11/07/2018  12:52 AM             1,601 mkproject.bat
    02/16/2020  10:47 PM             9,158 mkvirtualenv.bat
    11/07/2018  12:52 AM             1,050 rmvirtualenv.bat
    11/07/2018  12:52 AM             2,248 setprojectdir.bat
    08/05/2017  11:51 PM               422 toggleglobalsitepackages.bat
    11/07/2018  12:52 AM             2,326 virtualenvwrapper.bat
    11/07/2018  12:52 AM             1,608 vwenv.bat
    11/07/2018  12:52 AM               557 whereis.bat
    11/07/2018  12:52 AM             1,495 workon.bat
                  17 File(s)         25,653 bytes
    

    Could it be that pyenv-win doesn't handle paths with spaces or parenthesis?

  2. filipporemonato commented on Jul 19, 2021

    @filipporemonato
    Author

    Hei Bjorn, thank you for the comment., and for the clarifications about the .bat files in place of the .sh. That made it much clearer :)
    I have checked the other issue you linked (which also prompted me to edit the above by specifying I installed pyenv-win). It may be related, but it's hard for me to say.

    To give some additional info that you asked in the other issue: I have a Python 3.9 installed "from scratch" with the python.org downloadable, which gave me pip through which I installed pyenv-win, and later the Python 3.7 as described above. virtualenvwrapper-win is installed only in Python 3.7, but at the same time that version is the only one pyenv-win can see, checking with the command pyenv versions.

    There are no spaces or parenthesis on the path. The full path to the virtualwrapper executables (.bat) is C:\Users\filippor\.pyenv\pyenv-win\versions\3.7.6\Scripts. As far as I understand reading the doc for pyenv exec, the part of the path up to [...]\3.7.6 is automatically added by the pyenv-win's shims, so that then when I run the command mkvirtualenv, the command actually being run is Scripts\mkvirtualenv. It seems like the Command Prompt interprets the "Scripts" part as the command name, instead of the directory into which to search.
    To check if that works, I manually cd myself into C:\Users\filippor\.pyenv\pyenv-win\versions\3.7.6 and then ran Scripts\mkvirtualenv, and the command gets executed normally and I can create the virtualenv. Same goes for other commands given by virtualenvwrapper.
    Weirdly, I have checked the shims for, say, pip, and it's made in the same way, but pip works fine. So I am a bit stumbled here.

  3. dedale commented on Jul 20, 2021

    @dedale
    Collaborator

    I cannot reproduce:

    pyenv install 3.7.7
    pyenv local 3.7.7
    pip install virtualenvwrapper-win
    mkvirtualenv -h

    Usage: mkvirtualenv [mkvirtualenv-options] [virtualenv-options] DEST_DIR

    DEST_DIR The name of the envirnment to create (must be last).

    The new environment is automatically activated after being
    initialized.

    mkvirtualenv options:
    ...

  4. dedale commented on Jul 20, 2021

    @dedale
    Collaborator

    OK, I can reproduce when I run the command with the wrong Python activated:

    C:\Users\ded $ mkvirtualenv
    'Scripts' is not recognized as an internal or external command,
    operable program or batch file.

    Following your steps, mkvirtualenv is only available for one Python version, the one that was activated when pip run.
    So this works only when you activate the right Python version.

    I'll see what I can do to improve the error (should be something like command not found).

  5. filipporemonato commented on Jul 20, 2021

    @filipporemonato
    Author

    Hi dedale, note that you used pyenv local 3.7.7 instead of pyenv shell as in the issue posted above. See screenshot below, which I just reproduced:
    image

    EDIT - After dedale's second answer: It seems to me that the correct Python version is active in the screenshot above, that I verify with pyenv shell; it might be a conflict between the global/local/shell Python versions being used, perhaps? However, both pyenv global and pyenv local return "No global (local) version configured", so the only one active in my shell is the one from pyenv shell, which seems to be the right one.

  6. kirankotari commented on Jul 20, 2021

    @kirankotari
    Member

    Describe the bug
    I installed pyenv-win, and subsequently installed a new Python with version 3.7. In Python 3.7, I pip-installed virtualenvwrapper-win. Following the instructions on virtualenvwrapper, I tried running a command like mkvirtualenv, which returned "mkvirtualenv is not a recognized command". Then I remembered I had to rehash pyenv after the install, and so did pyenv rehahs. Now running mkvirtualenv gives "Scripts is not a recognized command".
    I also tried uninstalling and reinstalling virtualenvwrapper, with rehash right after both uninstall and reinstall, but the same error occurrs (see screenshot).

    To Reproduce
    Steps to reproduce the behavior:

    1. Install pyenv-win and new Python version, switch to that Python version with pyenv shell 3.7.6. Confirm correct Python version is active.
    2. Install virtualenvwrapper-win via pip install virtualenvwrapper-win
    3. Rehahs pyenv-win with pyenv rehahs
    4. See error

    Expected behavior
    To be able to run mkvirtualenv <env> or other commands related to virtualenvwrapper

    Screenshots
    image

    Desktop (please complete the following information):

    • OS: Windows 10
    • Tools used: Command Prompt (cmd)
    • Version: Pyenv-win version 2.64.8

    Additional context
    I also tried finding the file "virtualenvwrapper.sh", fillowing the instructions on virtualenvwrapper, but that file is nowhere to be found, I only find a "virtualenvwrapper.bat" inside [...]\.pyenv\pyenv-win\versions\3.7.6\Scripts.

    To Reproduce
    Step 1. Is wrong. Why? find the below explanation.
    pyenv shell <version> doesn't confirm correct python version. It sets the default python shell to the given version even you configure the pyenv local the python shell (interpreter) uses the default which is configured.

    If you wanted to validate the python is set, use following commands pyenv version or pyenv versions or pyenv version-name
    To set use following commands pyenv local <version> or pyenv global <version>

  7. filipporemonato commented on Jul 21, 2021

    @filipporemonato
    Author

    Hi Kirankotari,
    No, step 1 is correct. pyenv shell <version> sets the version of Python for the current shell. To confirm the active Python version one can then use pyenv shell,i.e. without the <version> argument, as explained in the help function. You can also see this in the screenshot I posted right above your reply. Perhaps I should have been more specific.
    After setting the Python version with step 1, the same version (i.e. 3.7.6) is shown as the active one by all of the commands pyenv shell, pyenv version, pyenv version-name, and pyenv versions (marked with a star).

  8. added 3 commits that reference this issue on Aug 17, 2021
    ba88f05
    811279c
    151ebf3
  9. added a commit that references this issue on Sep 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions