16

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 = ["iotahoe <iotahoe@iotahoe.com>"] # daniel.bell@hitachivantara.com / daniel@iotahoe.com
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.

  • How do I notate the latest version of a package? I assumed `"*"` did that. –  Jul 15 '21 at 14:46

4 Answers4

19

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.

finswimmer
  • 10,896
  • 3
  • 34
  • 44
  • 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. –  Jul 19 '21 at 08:02
  • How can I tell a package is built-in or not? Sorry for being a noob. –  Jul 19 '21 at 08:06
  • Doing `poetry init -n`, then `poetry add click` installed. However, `poetry add logging` threw `EnvCommandError`. `poetry add os` threw `ValueError`. –  Jul 19 '21 at 08:32
  • 1
    You'll find the list of built-in modules [here](https://docs.python.org/3/py-modindex.html). 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. – finswimmer Jul 19 '21 at 16:52
  • 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 above –  Jul 21 '21 at 13:00
  • Standard `poetry init` solved this for me; generating a `.lock` file. Tysm –  Aug 04 '21 at 09:47
  • 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) – lizziepika Feb 05 '23 at 01:23
  • 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) – lizziepika Feb 05 '23 at 01:23
  • 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.*]` configs – Sonic Soul May 22 '23 at 15:23
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.

Finch_Powers
  • 2,938
  • 1
  • 24
  • 34
  • 1
    Some practical advice on how to "flush egg-info" in the local file system would be appreciated! – Dima Tisnek Jul 15 '22 at 02:44
  • 1
    `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. – Finch_Powers Jul 15 '22 at 14:37
1

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

ayush23
  • 19
  • 1
0

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

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/34738565) – Poulpynator Jul 28 '23 at 12:51
  • 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](/help/how-to-answer). – Community Aug 01 '23 at 02:41