poetry icon indicating copy to clipboard operation
poetry copied to clipboard

poetry env remove with virtualenvs.in-project = true

Open fgervais opened this issue 4 years ago • 11 comments

  • [x] I am on the latest Poetry version.

  • [x] I have searched the issues of this repo and believe that this is not a duplicate.

  • [x] If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).

  • OS version and name: 18.04.3 LTS (Bionic Beaver)

  • Poetry version: Poetry version 1.0.5

  • Link of a Gist with the contents of your pyproject.toml file: https://gist.github.com/fgervais/5a33d9df4cca064f02ce7fa6136c7e5e

Issue

I think poetry env remove fails when virtualenvs.in-project = true

$ poetry env info

Virtualenv
Python:         3.6.9
Implementation: CPython
Path:           /home/fgervais/personal/test/.venv
Valid:          True

System
Platform: linux
OS:       posix
Python:   /usr

$ poetry config --list
cache-dir = "/home/fgervais/.cache/pypoetry"
virtualenvs.create = true
virtualenvs.in-project = true
virtualenvs.path = "{cache-dir}/virtualenvs"  # /home/fgervais/.cache/pypoetry/virtualenvs
$ poetry env remove 3.6.9

[ValueError]
Environment "test-dT4kcP9T-py3.6" does not exist.

fgervais avatar Mar 03 '20 20:03 fgervais

Found the same bug on macos:

$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.15.3
BuildVersion:	19D76

$ uname -a
Darwin Ems-MacBook-Pro 19.3.0 Darwin Kernel Version 19.3.0: Thu Jan  9 20:58:23 PST 2020; root:xnu-6153.81.5~1/RELEASE_X86_64 x86_64

esciara avatar Mar 10 '20 10:03 esciara

Same issue with a more relative command

$ poetry env remove .venv/bin/python

The current hotfix is to just remove .venv/. However, I am not sure if there's consequences like state changes in $POETRY_HOME


In addition, requesting more simple relative remove command

$ poetry env remove .

ketozhang avatar Apr 05 '20 21:04 ketozhang

Also encountered the same bug on macOS 11:

❯ sw_vers
ProductName:	macOS
ProductVersion:	11.4
BuildVersion:	20F71

❯ uname -a
Darwin hostname 20.5.0 Darwin Kernel Version 20.5.0: Sat May  8 05:10:33 PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64 x86_64

jidicula avatar Jun 07 '21 13:06 jidicula

Is this issue is still active? I found the same problem on macOS 11.6 Big Sur with Python 3.9 and poetry version 1.1.12:

$  poetry env remove .venv                                                                                     
/bin/sh: .venv: command not found

  EnvCommandError

  Command .venv -c "import sys; print('.'.join([str(s) for s in sys.version_info[:3]]))" errored with the following return code 127, and output: 
  

  at ~/Library/Application Support/pypoetry/venv/lib/python3.9/site-packages/poetry/utils/env.py:625 in remove
       621│                     shell=True,
       622│                 )
       623│             )
       624│         except CalledProcessError as e:
    →  625│             raise EnvCommandError(e)
       626│ 
       627│         python_version = Version.parse(python_version.strip())
       628│         minor = "{}.{}".format(python_version.major, python_version.minor)
       629│ 

deepaerial avatar Dec 28 '21 16:12 deepaerial

Have the exact same problem on Ubuntu with two env with similar python version but different locations.

Just removed .venv from project folder. Seems to be safe, as it disappeared from poetry env list !

sadransh avatar Feb 18 '22 02:02 sadransh

Same issue - can't find a way to use poetry env remove with .venv local virtual environment.

Getting errors like:

/bin/sh: 1: .venv: not found

  EnvCommandError

  Command .venv -c "import sys; print('.'.join([str(s) for s in sys.version_info[:3]]))" errored with the following return code 127, and output: 
  

  at ~/.poetry/lib/poetry/utils/env.py:625 in remove
       621│                     shell=True,
       622│                 )
       623│             )
       624│         except CalledProcessError as e:
    →  625│             raise EnvCommandError(e)
       626│ 
       627│         python_version = Version.parse(python_version.strip())
       628│         minor = "{}.{}".format(python_version.major, python_version.minor)

PeterBaker0 avatar Aug 11 '22 00:08 PeterBaker0

Same issue (Ubuntu 22.04). Interestingly, if the only virtual environment you have is a local .venv in your project, this works fine:

poetry env remove --all

geozeke avatar Oct 18 '22 19:10 geozeke

Same behavior also on Windows 10 (not mentioned by anyone before). I confirm that the workaround proposed by @geozeke works fine.

Eschivo avatar Dec 06 '22 14:12 Eschivo

I just came across the same problem. Using Poetry (version 1.2.2)

princelySid avatar Feb 14 '23 10:02 princelySid

I just came across the same problem. Using Poetry (version 1.2.2)

Latest version is 1.3.2. Did you try with that one ?

esciara avatar Feb 14 '23 15:02 esciara

I just came across the same problem. Using Poetry (version 1.2.2)

Latest version is 1.3.2. Did you try with that one ?

Yes. The error I got:

/bin/sh: .venv: command not found

Command .venv -c "import sys; print('.'.join([str(s) for s in sys.version_info[:3]]))" errored with the following return code 127, and output: 

princelySid avatar Feb 14 '23 15:02 princelySid

This issue still persists in 1.5.1. poetry env remove --all works for now.

yozachar avatar Jun 13 '23 14:06 yozachar

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Apr 11 '24 00:04 github-actions[bot]