8

When trying to install the Python dependencies with Poetry, I've the following error:

$ poetry install                                                                                                    
The currently activated Python version 2.7.15 is not supported by the project (>=3.6).
Trying to find and use a compatible version.
Using python3 (3.7.4)
Skipping virtualenv creation, as specified in config file.
Updating dependencies
Resolving dependencies... (1.7s)

[SolverProblemError]
The current project's Python requirement (>=3.6) is not compatible with some of the required packages Python requirement:
  - pre-commit requires Python >=3.6.1

Because no versions of pre-commit match >2.2.0,<3.0.0
 and pre-commit (2.2.0) requires Python >=3.6.1, pre-commit is forbidden.
So, because my-proj depends on pre-commit (^2.2.0), version solving failed.

Here is my environment:

$ python3 --version                                                                                                 
Python 3.7.4
$ poetry --version                                                                                                  
Poetry version 1.0.5
$ pre-commit --version                                                                                             
pre-commit 2.2.0

And a sample of my pyproject.toml:

...
[tool.poetry.dependencies]
python = ">=3.6"
...

[tool.poetry.dev-dependencies]
pre-commit = "^2.2.0"
...

I've tried changing the python version in pyproject to 3.7, but didn't change the result. And if I remove the pre-commit dependency, I've got the same error on another dependency.

I don't know what should I look for: upgrading/downgrading the versions, incompatible versions

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
Sergio Lema
  • 1,491
  • 1
  • 14
  • 25
  • well, what if you change it to `">=3.6.1"` in `pyproject.toml`? – Arne Mar 27 '20 at 11:34
  • If I change it to `>=3.6.1` it seems that it's now comparing with python 2.7: `The current project's Python requirement (2.7.15) is not compatible with some of the required packages Python requirement: - pre-commit requires Python >=3.6.1` – Sergio Lema Mar 27 '20 at 12:38
  • after changing something in the `poetry.tool` section you need to reinstall the application so that poetry can rebuild the virtualenv with the new specification. Also, from your error messages it seems that you have some kind of python env activated through `virtualenv`, maybe run `deactivate` before running `poetry install`. – Arne Mar 27 '20 at 13:07
  • 1
    This isn't really a problem related to programming or a tool though, it's your local setup that is causing issues for you. Any help given here will ultimately boil down to "try to make a clean setup, keeping to the poetry instructions as close as possible." – Arne Mar 27 '20 at 13:08
  • 1
    You're right @Arne. I've run `poetry config virtualenvs.create false` some time ago and the virtualenv wasn't created correctly for the project. After running `poetry config virtualenvs.create true` everything works fine. – Sergio Lema Mar 27 '20 at 13:37
  • 1
    good to know you solved it =) Feel free to self-answer this post if you think that you can get it into a general QA form, or if it's all too vague and won't help future googlers just closing the questions is also fine. – Arne Mar 27 '20 at 14:02

1 Answers1

6

As mentionned by @Arne in the comments, it seemed to be a virtualenv problem.

I've run poetry config virtualenvs.create false previously for another project and the configuration was set at a global level. Running the reverse command poetry config virtualenvs.create true solved the problem (maybe add --local to set it to individual projects).

Sergio Lema
  • 1,491
  • 1
  • 14
  • 25