Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to delete virtual env? #926

Closed
AgentCosmic opened this issue Mar 1, 2019 · 13 comments
Closed

How to delete virtual env? #926

AgentCosmic opened this issue Mar 1, 2019 · 13 comments
Labels
area/docs/faq Frequently duplicated/potential addition to FAQ kind/question User questions (candidates for conversion to discussion)

Comments

@AgentCosmic
Copy link

How do I delete a virtual env? I tried just deleting the file but poetry stopped working after that.

@andyg0808
Copy link

The latest preview version (which can be installed with get-poetry.py --preview; see the readme) supports poetry env remove, which will handle removing the virtualenv for you. remove expects one argument: the Python version to remove the virtualenv for. In my case, I'm using Python 3.7, so I usually type something like poetry env remove 3.7.

If you want to see where the virtualenv is stored, there are various ways to print it out. poetry env info, which is also new in the preview version, will print a nice summary of information about the current environment Poetry is using, including the full path to the virtualenv.

@Djailla
Copy link
Contributor

Djailla commented Apr 24, 2019

On macOS, envs are located here ~/Library/Caches/pypoetry/virtualenvs

@danielquinn
Copy link
Contributor

On Linux, the easiest way to find the virtualenv is to pop into a subshell and run which python:

$ poetry shell
$ which python

@arnegroskurth
Copy link

I feel like this should be easier. Maybe something like $ poetry destroy [-f] for the environment associated with the current working directory?

@abn
Copy link
Member

abn commented Aug 16, 2020

@arnegroskurth the poetry env remove <python> command does this.

As pointed out above you can also do rm -rf `poetry env info -p` to remoe the virtual env directory depending on what you need to do.

@arnegroskurth
Copy link

@abn Sure but that is more complicated and requires the user to know about the poetry env * commands. At least me (and I suspect quite a lot of other users) are only using poetry {install,update,add,remove} the vast majority of the time and are happy that everything regarding the venv is abstracted away from me.

So I feel like there should be something to just level the playing-field without me having to think about venvs again.

@abn
Copy link
Member

abn commented Aug 16, 2020

Sounds to me more like a deficiency in the documentation and/or onboarding guide for a new user to Poetry. That is definitely an area that we are interested in improving on.

At this time, I do not think we want to encourage the addition of multiple commands to do the same task. And, personally, adding something like poetry destroy does not really solve the issue, it is yet another command anyway that the user needs to know about. Additionally, it can also be ambiguous as it could also mean "destroy everything poetry related".

@abn abn added area/docs/faq Frequently duplicated/potential addition to FAQ kind/question User questions (candidates for conversion to discussion) labels Aug 16, 2020
@arnegroskurth
Copy link

@abn I just feel like that the benefit of using poetry over venv+pip is for the user to not have to care about two separate tools for dependency-management and project-isolation anymore. And because I can create and update the environment with top-level poetry commands, I feel like that I should also be able to remove the environment with a top-level command that is much more discoverable ($ poetry help) then anything under $ poetry env.

@abn
Copy link
Member

abn commented Aug 16, 2020

That definitely is one of the advantages of using poetry. Although, it is important to note that explicit creation of an environment relies on poetry env use <python>. What you are referring to is the implicit creation of the environment by commands that require an existing virtual environment. All commands relating to environment managent are already grouped under env.

We appreciate your feedback on this. However, for this matter I do not see a reason to change the current behaviour at this time.

@davnat
Copy link

davnat commented Sep 2, 2020

As pointed out above you can also do rm -rf `poetry env info -p` to remoe the virtual env directory depending on what you need to do.

Please note that the suggested command can be quite dangerous if accidentally run in a directory not handled by poetry.

@timkofu
Copy link

timkofu commented Oct 16, 2020

This worked for me:

  • cd into the folder where pyproject.toml is
  • Run poetry env list (this will show you the venv for that project)
  • Then run poetry env remove whatever-WhATeVs-py3.9 to delete it

Running poetry shell after will create a new venv, after which running poetry install will install all the deps listed in pyproject.toml.

@pavanmr94
Copy link

you can actually just run poetry env remove python from the project root folder and it will delete its virtualenv

@mattsta
Copy link

mattsta commented Dec 4, 2020

addendum: just note the python parameter is your python executable name (it isn't just an argument saying "delete python in this venv"—it's saying "use this executable name to lookup the venv name").

so, if your default path python isn't your venv python (e.g. /usr/bin/python is still 2.7, but you develop using /usr/local/bin/python3), you need to run poetry env remove python3 or else you'll get yelled at for not having a py2.7 venv

the lookup is here: execute code using the python argument to find python version then python version is appended to the venv directory. looks like the code is designed to support multi-python-version venvs for the same project, which makes sense, but caught me off guard with needing to fight system python vs. usable python.

@python-poetry python-poetry locked and limited conversation to collaborators Feb 13, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
area/docs/faq Frequently duplicated/potential addition to FAQ kind/question User questions (candidates for conversion to discussion)
Projects
None yet
Development

No branches or pull requests

10 participants