poetry install | SolverProblemError Because my_project depends on string (*) which doesn't match any versions, version solving failed
Asked Answered
B

5

25

I am yet to use poetry to run project, so excuse lack of understanding.

I successfully installed the poetry python library manager, using:

curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3

Next step poetry install initially returned this error:

me@LAPTOP-G1DAPU88:~/.ssh/workers-python/workers$ poetry install

  RuntimeError

  Poetry could not find a pyproject.toml file in /home/me/.ssh/workers-python/workers or its parents

  at ~/.poetry/lib/poetry/_vendor/py3.8/poetry/core/factory.py:369 in locate
      365│             if poetry_file.exists():
      366│                 return poetry_file
      367│
      368│         else:
    → 369│             raise RuntimeError(
      370│                 "Poetry could not find a pyproject.toml file in {} or its parents".format(
      371│                     cwd
      372│                 )
      373│             )

I soon realised I needed my own made pyproject.toml file. Running poetry install again yielded:

$ poetry install

  TOMLError

  Invalid TOML file /home/me/.ssh/workers-python/workers/pyproject.toml: Key "json " already exists.

  at ~/.poetry/lib/poetry/_vendor/py3.8/poetry/core/toml/file.py:34 in read
      30│     def read(self):  # type: () -> "TOMLDocument"
      31│         try:
      32│             return super(TOMLFile, self).read()
      33│         except (ValueError, TOMLKitError) as e:
    → 34│             raise TOMLError("Invalid TOML file {}: {}".format(self.path.as_posix(), e))
      35│
      36│     def __getattr__(self, item):  # type: (str) -> Any
      37│         return getattr(self.__path, item)
      38│

Above error indicates there were duplicate entries.

Running poetry install again with the now updated pyproject.toml file in cwd threw this error (in the post's title):

$ poetry install
Creating virtualenv my_project-1_EUeV5I-py3.8 in /home/me/.cache/pypoetry/virtualenvs
Updating dependencies
Resolving dependencies... (28.4s)

  SolverProblemError

  Because my_project depends on string (*) which doesn't match any versions, version solving failed.

  at ~/.poetry/lib/poetry/puzzle/solver.py:241 in _solve
      237│             packages = result.packages
      238│         except OverrideNeeded as e:
      239│             return self.solve_in_compatibility_mode(e.overrides, use_latest=use_latest)
      240│         except SolveFailure as e:
    → 241│             raise SolverProblemError(e)
      242│
      243│         results = dict(
      244│             depth_first_search(
      245│                 PackageNode(self._package, packages), aggregate_package_nodes

However, temporarily removing all instances = "*" gave me this error of \n on line 12... which doesn't appear to be there:

$ poetry install

  TOMLError

  Invalid TOML file /home/me/.ssh/workers-python/workers/pyproject.toml: Unexpected character: '\n' at line 12 col 5

  at ~/.poetry/lib/poetry/_vendor/py3.8/poetry/core/toml/file.py:34 in read
      30│     def read(self):  # type: () -> "TOMLDocument"
      31│         try:
      32│             return super(TOMLFile, self).read()
      33│         except (ValueError, TOMLKitError) as e:
    → 34│             raise TOMLError("Invalid TOML file {}: {}".format(self.path.as_posix(), e))
      35│
      36│     def __getattr__(self, item):  # type: (str) -> Any
      37│         return getattr(self.__path, item)
      38│
me@LAPTOP-G1DAPU88:~/.ssh/workers-python/workers$ cat pyproject.toml
[tool.poetry]
name = "my_project"
version = "0.1.0"
description = "Top-level package for my_project."
authors = [""]
packages = [
    { include = "my_project"},
]

[tool.poetry.dependencies]
python = "^3.8"
click  # Suspect line

I have reverted this.


Current pyproject.toml:

[tool.poetry]
name = "data_simulator"
version = "0.1.0"
description = "Top-level package for data_simulator."
authors = ["email <[email protected]>"] # [email protected] / [email protected]
packages = [
    { include = "data_simulator"},
]

[tool.poetry.dependencies]
python = "^3.8"
click = "*"
#logging = "*"
#os = "*"
#pathlib = "*"
#time = "*"
numpy = "*"
pandas = "*"
#json = "*"
#random = "*"
faker = "*"
transformers = "4.4.2"
#re = "*"
#itertools = "*"
#datetime = "*"
#requests = "*"
#copy = "*"
#collections = "*"
#collections.abc = "*"
#multiprocessing = "*"
#multiprocessing.dummy = "*"
nltk = "*"
#nltk.corpus = "*"
#string = "*"

[tool.poetry.dev-dependencies]
isort = "5.6.4"
black = "^20.8b1"
invoke = "^1.4.1"
coveralls = "^2.2.0"
pytest = "^3.0"
flake8 = "^3.8.3"
mypy = "^0.782"

[[tool.poetry.source]]
name = "azure"
url = "https://pkgs.dev.azure.com/iotahoe/Halo/_packaging/private-sources/pypi/simple/"
secondary = true

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

Note: 'name', 'authors', 'include', 'url' have been censored.

Bertram answered 15/7, 2021 at 14:12 Comment(1)
How do I notate the latest version of a package? I assumed "*" did that.Bertram
S
30

As a general advise I recommend to use poetry's command line instead of creating/manipulating the pyproject.toml.

Start with a poetry init or poetry init -n and add your dependencies with poetry add.

The problem with your current pyproject.toml is, that you declare built-in packages as dependencies, like os, pathlib, string and others. This is why you receive the message Because my_project depends on string (*) which doesn't match any versions, version solving failed., which means poetry cannot find any matching package information in the repository.

Stupefaction answered 17/7, 2021 at 12:1 Comment(9)
I've never come across these commands. I will try this all out myself now. Great that you guessed that I had made the file manually. I will report back if in doubt. Ty.Bertram
How can I tell a package is built-in or not? Sorry for being a noob.Bertram
Doing poetry init -n, then poetry add click installed. However, poetry add logging threw EnvCommandError. poetry add os threw ValueError.Bertram
You'll find the list of built-in modules here. I wonder how you collected your list of dependencies. Usually you should be aware during programming whether you need to install a dependency or if it works out of the box.Stupefaction
I commented out all of the libraries that are built-in, based on your link. I get the same error for all libraries it seems. Haven't a clue what I'm doing wrong. However, I have been making this file manually. I have the lastest in my post aboveBertram
Standard poetry init solved this for me; generating a .lock file. TysmBertram
Thank you for this answer! I tried poetry install {library} and had no idea it was poetry add {library} to install (also tried editing the pyproject.toml which gave weird errs)Tercentenary
Thank you for this answer! I tried poetry install {library} and had no idea it was poetry add {library} to install (also tried editing the pyproject.toml which gave weird errs)Tercentenary
there's absolutely nothing wrong with modifying pyproject.toml. the lock file should be auto generated. you can certainly use update commands for versions but there's a ton of settings that need to be set manually such as [tool.*] configsSciential
A
7

Removing old poetry.lock has solved for me

Anthea answered 23/9, 2023 at 16:24 Comment(0)
S
2

tl;dr: Flush the *.egg-info directories before running poetry lock.

This answer is not strictly related to the current issue, but a similar error message can appear in other circumstances, so I think it's valuable to share it here.

If you are locking in a project where sub-dependencies are directly available on the file system, some *.egg-info directories may interfere with the locking process, causing issues when trying to run poetry install in a context where those *.egg-info files are missing. To avoid the problem: Flush the *.egg-info directories prior to locking. You should then have an updated poetry.lock file with more content.

Sickroom answered 27/1, 2022 at 17:2 Comment(2)
Some practical advice on how to "flush egg-info" in the local file system would be appreciated!Sourdough
find . -name *.egg-info | xargs rm -r This will look into the current working directory and all sub directories, find all of the egg-info and rm them.Sickroom
T
2

Try deleting the poetry.lock and run the command poetry install to create a new poetry file. Worked for me as well

Triazine answered 24/7, 2023 at 15:46 Comment(2)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewRuckus
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Petrochemistry
I
1

Try deleting the poetry.lock and run the command poetry install to create a new poetry file. Worked for me

Impressive answered 28/2, 2023 at 6:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.