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

1.2.0rc1 - poetry env - Current Python version conflict with pre-existing virtualenv #6222

Closed
3 tasks done
xkortex opened this issue Aug 23, 2022 · 6 comments · Fixed by #6225
Closed
3 tasks done
Labels
kind/bug Something isn't working as expected

Comments

@xkortex
Copy link

xkortex commented Aug 23, 2022

  • OS version and name: macOS catalina 10.15.7 (19H1922)
  • Poetry version: 1.2.0rc.1
  • Link of a Gist with the contents of your pyproject.toml file:
[tool.poetry]
name = "test-project"
version = "0.1.0"
description = ""
authors = <redacted>
readme = "README.md"
packages = [{include = "test_project"}]

[tool.poetry.dependencies]
python = "^3.8"  # also tried this process with ">3.8,<3.9" to try to force it not to use 3.9

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
  • config
❯ cat ~/Library/Preferences/pypoetry/config.toml
[virtualenvs]
create = false

[experimental]
new-installer = true

[installer]
parallel = true

Issue

Apologies in advance if this is a PEBCAK, but I'm following the docs as closely as possible and it's not conforming with my expectations, so I think there is a mismatch somewhere. I've been experimenting with the 1.2 rc because I'm super excited for it, and running into some friction. I'm interested in running poetry-version-plugin

I've just installed poetry 1.2.0rc1 via https://install.python-poetry.org (md5sum 6687215717deb5c6d8b86bbca2c043d8)

❯ python3 ~/install-poetry.py --version 1.2.0rc1  # python3 points to ../Cellar/[email protected]/3.9.12/bin/python3
...
It will add the `poetry` command to Poetry's bin directory, located at:

/Users/mike/Library/Python/3.9/bin
...
❯ ln -svf /Users/mike/Library/Python/3.9/bin/poetry ~/.local/bin/poetry
/Users/mike/.local/bin/poetry -> /Users/mike/Library/Python/3.9/bin/poetry
❯ poetry --version
Poetry (version 1.2.0rc1)

I've then activated my virtual environment (I have virtualenvs.create=false and like to manage my own venvs). Now, I presume I should be able to run poetry self add poetry-version-plugin or poetry self show plugins and see existing plugins as a baseline (should see none). But instead I see

❯ poetry self show plugins -vvv
Loading configuration file /Users/mike/Library/Preferences/pypoetry/config.toml
Loading configuration file /Users/mike/Library/Preferences/pypoetry/auth.toml

...
  InvalidCurrentPythonVersionError

  Current Python version (3.8.13) is not allowed by the project (3.9.12).
  Please change python executable via the "env use" command.

  at ~/Library/Application Support/pypoetry/venv/lib/python3.9/site-packages/poetry/utils/env.py:844 in create_venv
       840│             current_python = Version.parse(
       841│                 ".".join(str(c) for c in env.version_info[:3])
       842│             )
       843│             if not self._poetry.package.python_constraint.allows(current_python):
    →  844│                 raise InvalidCurrentPythonVersionError(
       845│                     self._poetry.package.python_versions, str(current_python)
       846│                 )
       847│             return env

Mismatch with what poetry env info shows:

❯ poetry env info

Virtualenv
Python:         3.8.13
Implementation: CPython
Path:           /Users/mike/.virtualenvs/core38c
Executable:     /Users/mike/.virtualenvs/core38c/bin/python
Valid:          True

System
Platform:   darwin
OS:         posix
Python:     3.8.13
Path:       /Users/mike/.pyenv/versions/3.8.13
Executable: /Users/mike/.pyenv/versions/3.8.13/bin/python3.8

Python 3.9.12 is my "system" python, managed by homebrew, but I manage all my python versions manually using pyenv and virtualenv. I want my poetry installation completely decoupled from the virtualenvs, but maybe that is not possible with the plugins, and/or with virtualenvs.create=false? I tried setting virtualenvs.create true but I get the same error.

❯ poetry env use /Users/mike/.pyenv/versions/3.8.13/bin/python3
Creating virtualenv test-project-QU_ARkle-py3.8 in /Users/mike/Library/Caches/pypoetry/virtualenvs
Using virtualenv: /Users/mike/Library/Caches/pypoetry/virtualenvs/test-project-QU_ARkle-py3.8
❯ poetry self show plugins -vvv
...
  InvalidCurrentPythonVersionError

  Current Python version (3.8.13) is not allowed by the project (3.9.12).
  Please change python executable via the "env use" command.

  at ~/Library/Application Support/pypoetry/venv/lib/python3.9/site-packages/poetry/utils/env.py:844 in create_venv
       840│             current_python = Version.parse(
       841│                 ".".join(str(c) for c in env.version_info[:3])
       842│             )
       843│             if not self._poetry.package.python_constraint.allows(current_python):
    →  844│                 raise InvalidCurrentPythonVersionError(
       845│                     self._poetry.package.python_versions, str(current_python)
       846│                 )
       847│             return env

If I completely deactivate, and then run it, the command succeeds, but in doing so it creates a 3.9 environment, which I don't want.

❯ deactivate

❯ poetry env use /Users/mike/.pyenv/versions/3.8.13/bin/python3
Using virtualenv: /Users/mike/Library/Caches/pypoetry/virtualenvs/test-project-QU_ARkle-py3.8

❯ poetry self show plugins -vvv
Loading configuration file /Users/mike/Library/Preferences/pypoetry/config.toml
Loading configuration file /Users/mike/Library/Preferences/pypoetry/auth.toml
Creating virtualenv poetry-instance-YN-Fucdl-py3.9 in /Users/mike/Library/Caches/pypoetry/virtualenvs
Using virtualenv: /Users/mike/Library/Caches/pypoetry/virtualenvs/poetry-instance-YN-Fucdl-py3.9

  • poetry-plugin-export (1.0.6) Poetry plugin to export the dependencies to various formats
      1 application plugin

      Dependencies
        - poetry (>=1.2.0b3,<2.0.0)
        - poetry-core (>=1.1.0b3,<2.0.0)

As soon as I activate my normal env, and run poetry self show, it barfs.

Seems alright if I do everything "by the book" and use fully Poetry-managed virtualenvs, but I'd really like to keep my existing workflow with external virtualenvs.

@xkortex xkortex added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Aug 23, 2022
@xkortex
Copy link
Author

xkortex commented Aug 23, 2022

Here's the full stacktrack:

❯ poetry self show plugins -vvv
Loading configuration file /Users/mike/Library/Preferences/pypoetry/config.toml
Loading configuration file /Users/mike/Library/Preferences/pypoetry/auth.toml

  Stack trace:

  8  ~/Library/Application Support/pypoetry/venv/lib/python3.9/site-packages/cleo/application.py:329 in run
      327│
      328│             try:
    → 329│                 exit_code = self._run(io)
      330│             except Exception as e:
      331│                 if not self._catch_exceptions:

  7  ~/Library/Application Support/pypoetry/venv/lib/python3.9/site-packages/poetry/console/application.py:185 in _run
      183│         self._load_plugins(io)
      184│
    → 185│         exit_code: int = super()._run(io)
      186│         return exit_code
      187│

  6  ~/Library/Application Support/pypoetry/venv/lib/python3.9/site-packages/cleo/application.py:423 in _run
      421│             io.input.set_stream(stream)
      422│
    → 423│         exit_code = self._run_command(command, io)
      424│         self._running_command = None
      425│

  5  ~/Library/Application Support/pypoetry/venv/lib/python3.9/site-packages/cleo/application.py:465 in _run_command
      463│
      464│         if error is not None:
    → 465│             raise error
      466│
      467│         return event.exit_code

  4  ~/Library/Application Support/pypoetry/venv/lib/python3.9/site-packages/cleo/application.py:446 in _run_command
      444│
      445│         try:
    → 446│             self._event_dispatcher.dispatch(event, COMMAND)
      447│
      448│             if event.command_should_run():

  3  ~/Library/Application Support/pypoetry/venv/lib/python3.9/site-packages/cleo/events/event_dispatcher.py:23 in dispatch
       21│
       22│         if listeners:
    →  23│             self._do_dispatch(listeners, event_name, event)
       24│
       25│         return event

  2  ~/Library/Application Support/pypoetry/venv/lib/python3.9/site-packages/cleo/events/event_dispatcher.py:84 in _do_dispatch
       82│                 break
       83│
    →  84│             listener(event, event_name, self)
       85│
       86│     def _sort_listeners(self, event_name: str) -> None:

  1  ~/Library/Application Support/pypoetry/venv/lib/python3.9/site-packages/poetry/console/application.py:293 in configure_env
      291│
      292│         env_manager = EnvManager(poetry)
    → 293│         env = env_manager.create_venv(io)
      294│
      295│         if env.is_venv() and io.is_verbose():

  InvalidCurrentPythonVersionError

  Current Python version (3.8.13) is not allowed by the project (3.9.12).
  Please change python executable via the "env use" command.

  at ~/Library/Application Support/pypoetry/venv/lib/python3.9/site-packages/poetry/utils/env.py:844 in create_venv
       840│             current_python = Version.parse(
       841│                 ".".join(str(c) for c in env.version_info[:3])
       842│             )
       843│             if not self._poetry.package.python_constraint.allows(current_python):
    →  844│                 raise InvalidCurrentPythonVersionError(
       845│                     self._poetry.package.python_versions, str(current_python)
       846│                 )
       847│             return env
       ```

@dimbleby
Copy link
Contributor

surely a duplicate of the issues that you already identified as being the same

@xkortex
Copy link
Author

xkortex commented Aug 23, 2022

Perhaps, but crucially, I'm not using poetry install at all, and also this report has a bunch of additional details.

If you wish, I can merge this into 6141, if that lessens the maintenance burden for you kind folks.

@dimbleby
Copy link
Contributor

dimbleby commented Aug 23, 2022

I've no interest in investigating this one, its existence is no burden on me. I'm simply noting that it's surely a duplicate of the issues you already identified as being the same.

@finswimmer
Copy link
Member

Hello @xkortex,

thanks a lot for reporting 👍 Fix is in progress (#6225).

fin swimmer

Secrus pushed a commit that referenced this issue Aug 24, 2022
At the moment a venv is created on running a `poetry self` command. Even if it is not used in the command itself it's unnecessary and lead to problems as reported in #6222. This PR fixes this.

Resolves: #6222
@mkniewallner mkniewallner removed the status/triage This issue needs to be triaged label Sep 18, 2022
Copy link

github-actions bot commented Mar 1, 2024

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 Mar 1, 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.

4 participants