Skip to content
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

Poetry says that "environment seems to be broken" all the time #2756

Closed
3 tasks done
keddad opened this issue Jul 31, 2020 · 10 comments · Fixed by #2771
Closed
3 tasks done

Poetry says that "environment seems to be broken" all the time #2756

keddad opened this issue Jul 31, 2020 · 10 comments · Fixed by #2771
Labels
kind/bug Something isn't working as expected

Comments

@keddad
Copy link

keddad commented Jul 31, 2020

  • I am on the latest Poetry version.

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

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

  • OS version and name: Fedora 32

  • Poetry version: 1.0.10

  • Link of a Gist with the contents of your pyproject.toml file: Link

  • I've also done poetry config virtualenvs.path .venv

Issue

Apparently, poetry invalidates virtual environment even if literally nothing happened to it. Here is an example where I install a package and and try to list packages, but it says that environment is broken and installs it again: Gist. My only idea is that PyCharm, which is configured to use the venv, messes something up but it shouldn't write anything in venv, I guess.

@keddad keddad added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Jul 31, 2020
@finswimmer
Copy link
Member

@keddad I encountered this problem, when the venv is activated and poetry detect it as broken and than try to recreate it. So make sure your venv is deactivated and run poetry install once again. Afterwards everything should work normal.

@keddad
Copy link
Author

keddad commented Jul 31, 2020

Sadly, that didn't really work in my case. I'm clearly not running any venvs:

[keddad@localhost socialcomp]$ which python
/usr/bin/python

but poetry install && poetry show still results in "broken environment" issues.

@keddad
Copy link
Author

keddad commented Jul 31, 2020

Ok, that's clearly an issue with how VirtualEnv.is_sane() works. It simply checks if there are python and pip present:

def is_sane(self): # 
        # A virtualenv is considered sane if both "python" and "pip" exist.
        return os.path.exists(self._bin("python")) and os.path.exists(self._bin("pip"))


github.com/python-poetry/poetry/blob/master/poetry/utils/env.py#L1168

Since after poetry install my venv contains there files, it is probably looking for them in the wrong spot.

@keddad
Copy link
Author

keddad commented Jul 31, 2020

I've recorded a trace of poetry show running with a "broken env". I'm not really sure why is that happening, but here is a thing:

  • It removes my venv 22146 rmdir(".venv/socialcomp-nXpxZNnR-py3.8") = 0
  • And only then checks if pip binary exists 22149 stat("/home/keddad/Documents/hseproject/socialcomp/.venv/socialcomp-nXpxZNnR-py3.8/bin/pip", 0x7ffe35267450) = -1 ENOENT (Нет такого файла или каталога)

But I'm still not sure on why is this happening

@taranlu-houzz
Copy link

I think I am also running into the same issue.

I have a local poetry.toml:

[virtualenvs]
path = ".venv"

And virtualenvs.in-project is set to false globally.

@finswimmer
Copy link
Member

Ah, now I see what's going on. At the moment you cannot point virtualenvs.path to .venv as this is some kind of reserved location for poetry. Whenever it finds a .venv folder within the project it asumes that this is the folder with the venv. But this is not the case here with this setting, because it just defines the root folder in which the folders for the venvs will be placed.

Related: #1770

fin swimmer

@abn abn closed this as completed in #2771 Sep 23, 2020
abn pushed a commit that referenced this issue Sep 23, 2020
Before this change, when .venv directory exists  within the project 
root, poetry will use it as the path to the venv regardless whether 
virtualenvs.in-project is set to true or not. This leads to confusion
as described in #1770 and #2756.

With this change poetry will check if virtualenvs.in-project is set to
true if it finds a .venv folder.

This commit also changes the default state of this configuration to be
unset (null), in order to not break any current environments.

Resolves: #1770 #2756
@abn abn removed the status/triage This issue needs to be triaged label Sep 25, 2020
@HuM4NoiD
Copy link

HuM4NoiD commented Sep 1, 2022

I am still facing this issue, every time I use any poetry command in the project directory

poetry config:

cache-dir = "C:\\Users\\jugal.mistry\\AppData\\Local\\pypoetry\\Cache"
experimental.new-installer = true
installer.parallel = true
virtualenvs.create = true
virtualenvs.in-project = true
virtualenvs.path = "{cache-dir}\\virtualenvs"  # C:\Users\jugal.mistry\AppData\Local\pypoetry\Cache\virtualenvs

This creates a .venv in any new poetry project

On further inspection I found out that pip executable/script was not present in .venv/Scripts/

@neersighted
Copy link
Member

This is a really old issue and if you're currently experiencing this, I suggest you open a new issue with a reproduction. Make sure that you do not have an existing venv active (especially a deleted or partially broken one) before you run Poetry commands if you want virtualenvs.in-project to be respected and for Poetry to choose the in-project env (as an activate env will always override the Poetry env, unless it is invalid).

poetry env info is also your friend when it comes to debugging this.

@Photon1c
Copy link

This went away for me when I deactivated my environment and just let poetry create it itself through the automated installation process.

Copy link

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 github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants