Search code examples
python-3.xvirtualenvpython-poetrypyyaml

Unable to install PyYaml using Poetry


I'm trying to build a virtual environment using Poetry v1.7.1 on Mac, thru poetry install with a pyproject.toml like this:

[tool.poetry]
...

[tool.poetry.dependencies]
python = "^3.9"
mlrun = "1.4.1"
torch = "1.13.1"
transformers = "4.20"
sentence-transformers = "2.2.2"
scikit-learn = "1.2.2"
tensorboard = "2.12.2"
tqdm = "4.65.0"
attr = "0.3.2"
attrs = "23.1.0"
cattrs = "23.2.3"
ruamel-yaml-clib = "0.2.2"
ruamel-yaml = "0.16.10"
emoji = "2.4.0"
s3fs = "2023.1.0"

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

However, I always get this error:

Package operations: 38 installs, 2 updates, 0 removals

  • Downgrading attrs (23.2.0 -> 23.1.0)
  • Updating pyyaml (5.3 -> 5.4.1): Failed

  ChefBuildError

  Backend subprocess exited when trying to invoke get_requires_for_build_wheel
  
  running egg_info
  writing lib3/PyYAML.egg-info/PKG-INFO
  writing dependency_links to lib3/PyYAML.egg-info/dependency_links.txt
  writing top-level names to lib3/PyYAML.egg-info/top_level.txt
  Traceback (most recent call last):
    File "/Users/george/Library/Application Support/pypoetry/venv/lib/python3.10/site-packages/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
      main()
    File "/Users/george/Library/Application Support/pypoetry/venv/lib/python3.10/site-packages/pyproject_hooks/_in_process/_in_process.py", line 335, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "/Users/george/Library/Application Support/pypoetry/venv/lib/python3.10/site-packages/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
      return hook(config_settings)
    File "/var/folders/ly/152vxfld44sd8wg4pvj_g6w00000gn/T/tmpyejafm7e/.venv/lib/python3.10/site-packages/setuptools/build_meta.py", line 325, in get_requires_for_build_wheel
      return self._get_build_requires(config_settings, requirements=['wheel'])
    File "/var/folders/ly/152vxfld44sd8wg4pvj_g6w00000gn/T/tmpyejafm7e/.venv/lib/python3.10/site-packages/setuptools/build_meta.py", line 295, in _get_build_requires
      self.run_setup()
    File "/var/folders/ly/152vxfld44sd8wg4pvj_g6w00000gn/T/tmpyejafm7e/.venv/lib/python3.10/site-packages/setuptools/build_meta.py", line 311, in run_setup
      exec(code, locals())
    File "<string>", line 271, in <module>
    File "/var/folders/ly/152vxfld44sd8wg4pvj_g6w00000gn/T/tmpyejafm7e/.venv/lib/python3.10/site-packages/setuptools/__init__.py", line 103, in setup
      return distutils.core.setup(**attrs)
    File "/var/folders/ly/152vxfld44sd8wg4pvj_g6w00000gn/T/tmpyejafm7e/.venv/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 185, in setup
      return run_commands(dist)
    File "/var/folders/ly/152vxfld44sd8wg4pvj_g6w00000gn/T/tmpyejafm7e/.venv/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
      dist.run_commands()
    File "/var/folders/ly/152vxfld44sd8wg4pvj_g6w00000gn/T/tmpyejafm7e/.venv/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
      self.run_command(cmd)
    File "/var/folders/ly/152vxfld44sd8wg4pvj_g6w00000gn/T/tmpyejafm7e/.venv/lib/python3.10/site-packages/setuptools/dist.py", line 963, in run_command
      super().run_command(command)
    File "/var/folders/ly/152vxfld44sd8wg4pvj_g6w00000gn/T/tmpyejafm7e/.venv/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
      cmd_obj.run()
    File "/var/folders/ly/152vxfld44sd8wg4pvj_g6w00000gn/T/tmpyejafm7e/.venv/lib/python3.10/site-packages/setuptools/command/egg_info.py", line 321, in run
      self.find_sources()
    File "/var/folders/ly/152vxfld44sd8wg4pvj_g6w00000gn/T/tmpyejafm7e/.venv/lib/python3.10/site-packages/setuptools/command/egg_info.py", line 329, in find_sources
      mm.run()
    File "/var/folders/ly/152vxfld44sd8wg4pvj_g6w00000gn/T/tmpyejafm7e/.venv/lib/python3.10/site-packages/setuptools/command/egg_info.py", line 551, in run
      self.add_defaults()
    File "/var/folders/ly/152vxfld44sd8wg4pvj_g6w00000gn/T/tmpyejafm7e/.venv/lib/python3.10/site-packages/setuptools/command/egg_info.py", line 589, in add_defaults
      sdist.add_defaults(self)
    File "/var/folders/ly/152vxfld44sd8wg4pvj_g6w00000gn/T/tmpyejafm7e/.venv/lib/python3.10/site-packages/setuptools/command/sdist.py", line 112, in add_defaults
      super().add_defaults()
    File "/var/folders/ly/152vxfld44sd8wg4pvj_g6w00000gn/T/tmpyejafm7e/.venv/lib/python3.10/site-packages/setuptools/_distutils/command/sdist.py", line 251, in add_defaults
      self._add_defaults_ext()
    File "/var/folders/ly/152vxfld44sd8wg4pvj_g6w00000gn/T/tmpyejafm7e/.venv/lib/python3.10/site-packages/setuptools/_distutils/command/sdist.py", line 336, in _add_defaults_ext
      self.filelist.extend(build_ext.get_source_files())
    File "<string>", line 201, in get_source_files
    File "/var/folders/ly/152vxfld44sd8wg4pvj_g6w00000gn/T/tmpyejafm7e/.venv/lib/python3.10/site-packages/setuptools/_distutils/cmd.py", line 107, in __getattr__
      raise AttributeError(attr)
  AttributeError: cython_sources
  

  at ~/Library/Application Support/pypoetry/venv/lib/python3.10/site-packages/poetry/installation/chef.py:164 in _prepare
      160│ 
      161│                 error = ChefBuildError("\n\n".join(message_parts))
      162│ 
      163│             if error is not None:
    → 164│                 raise error from None
      165│ 
      166│             return path
      167│ 
      168│     def _prepare_sdist(self, archive: Path, destination: Path | None = None) -> Path:

Note: This error originates from the build backend, and is likely not a problem with poetry but with pyyaml (5.4.1) not supporting PEP 517 builds. You can verify this by running 'pip wheel --no-cache-dir --use-pep517 "pyyaml (==5.4.1)"'.

Following this thread, I tried adding this line to the toml file, but got an error:

The Poetry configuration is invalid:
  - data.dependencies.PyYAML must be valid exactly by one definition (0 matches found)

I also tried upgrading PIP, and testing different versions by adding pyyaml = "6.0.1" in the toml file...I even tested different Python versions, and installed package one by one. Still no luck.

I also wanted to try this way: https://github.com/yaml/pyyaml/issues/736, but it seems there's no way to set environment variables in pyproject.toml....Can someone please help? Thanks


Solution

  • It turns out you can download the wheel file and place it in the working dir and specify the file name in the toml file:

    pyyaml = {file = "PyYAML-5.4.1-cp39-cp39-macosx_10_9_x86_64.whl"}

    This now allows me to install PyYaml successfully.