1

I'm want to install a package from github.

The settings of package are as below:

pyproject.toml

...
build = "build.py"

[tool.poetry.dependencies]
python = "^3.7"

[build-system]
requires = ["poetry-core>=1.0.0", "cython"]
build-backend = "poetry.core.masonry.api"

build.py

from Cython.Build import cythonize
from distutils.command.build_ext import build_ext

def build(setup_kwargs):
    setup_kwargs.update({
        'ext_modules': cythonize(["asyncmy/*.pyx"],
                                 language_level=3,
                                 compiler_directives={'linetrace': True}),
        'cmdclass': {'build_ext': build_ext}
    })

setup.cfg

[flake8]
ignore = E501,W503,E203

I'm working on [MSC v.1900 64 bit (AMD64)] on win32 with python3.7.7 + pip 21.0.1 and when I install this package with

python -m pip install .

I got error like

ERROR: Could not build wheels for asyncmy which use PEP 517 and cannot be installed directly

But if I add a setup.py

# setup.py

import setuptools;setuptools.setup()

the package can be installed correctly, so what's wrong with the config?

Thanks.

Arne
  • 17,706
  • 5
  • 83
  • 99
jia Jimmy
  • 1,693
  • 2
  • 18
  • 38

1 Answers1

1

pip can't use poetry as a build backend, you need to build/install this project with poetry.

If you are on a *nix workstation, you can run curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python - to install it (see the docs for details). Once that is done, run poetry install instead of python -m pip install . to get a dev-installation (including virtualization) of the project.


If you want to create a distributable that you can upload to a package index or install directly with pip, run poetry build.

Arne
  • 17,706
  • 5
  • 83
  • 99
  • Do you mean that it can't be packed and upload to `pypi` for `pip install`? – jia Jimmy Mar 18 '21 at 02:57
  • It can be, it's even easier because you don't need an additional library to handle the publishing for you. `poetry build` will create a wheel-distribution for you, which are the artifacts you'd want to upload to a pypi. poetry can handle that step for you with `poetry publish` (see [the docs](https://python-poetry.org/docs/cli/#publish) for details). By the time someone installs your package with `pip install`, the fact that it was build with poetry is irrelevant, it will just work. – Arne Mar 18 '21 at 10:29
  • But I'm confusing why the module `asyncmy` [asyncmy](https://github.com/long2ice/asyncmy) cannot be installed in windows platform by `pip install ` Can u help me with that? – jia Jimmy Mar 19 '21 at 04:02
  • I can try to reproduce it once I reach my windows pc. but form a glance at their pypi entry I can see that they don't upload wheels for windows, only linux. They uploaded a source distribution, which pip downloads and then tries to build locally. When it does that, pip sees the `pyproject.toml` file and assumes that it can't decide which backend it should chose. You might be able to fix it by upgrading your pip to the latest version, which should be able to parse the pypoject file correctly. – Arne Mar 19 '21 at 08:24
  • I don't know how much you know about the python packaging process, but fyi, poetry puts a proper `setup.py` file into its source distributions, so theoretically pip *should* be able to build the package for you, and you really just need a recent version that supports pep 517 (version 19.0 and higher, I think). – Arne Mar 19 '21 at 08:27
  • If upgrading pip solves the issue, please do tell me, so that I can update the answer accordingly. – Arne Mar 19 '21 at 08:39
  • Glad for your patience. But I'm sure that i'm working with `[MSC v.1900 64 bit (AMD64)] on win32` with `python3.7.7` + `pip 21.0.1` and cannot install the module – jia Jimmy Mar 19 '21 at 08:55
  • Any other advise for solving the issue, thanks – jia Jimmy Mar 19 '21 at 09:03
  • 1
    well, I got curious enough to boot up me other machine and can reproduce the bug that you posted in the issue you created on the project. There is no simple solution I'm afraid, it would take me some time to debug that. Someone with experience with both cython and windows might stumble over this issue and provide some insight. – Arne Mar 19 '21 at 09:30