question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Install install_requires before running python setup.py bdist_wheel

See original GitHub issue

Environment

  • pip version: 19.0.1
  • Python version: CPython 3.7

Description

pip executes python setup.py bdist_wheel before installing the packages listed in install_requires.

For a simple package depending on numpy, using numpy in setup.py but such that python setup.py egg_info works fine without numpy, it shouldn’t be necessary to use setup_requires (and to have a setup.py compatible with setup_requires, which is not easy).

From https://pip.pypa.io/en/latest/reference/pip_install/#installation-order

Although the new install order is not intended to replace (and does not replace) the use of setup_requires to declare build dependencies, it may help certain projects install from sdist (that might previously fail) that fit the following profile:

  • They have build dependencies that are also declared as install dependencies using install_requires.
  • python setup.py egg_info works without their build dependencies being installed.
  • For whatever reason, they don’t or won’t declare their build dependencies using setup_requires.

For example, for this setup.py

import sys
from setuptools import setup

if "egg_info" in sys.argv:
    setup()
    sys.exit()

import numpy as np

setup()

and this setup.cfg:

[metadata]
name = irequires

[options]
install_requires =
    numpy

the command pip install . fails with

Processing /home/users/augier3pi/Dev/try_py_dependencies/irequires
Collecting numpy (from irequires==0.0.0)
  Using cached https://files.pythonhosted.org/packages/3d/10/62224c551acfd3a3583ad16d1e0f1c9e9c333e74479dc51977c31836119c/numpy-1.16.0-cp37-cp37m-manylinux1_x86_64.whl
Building wheels for collected packages: irequires
  Building wheel for irequires (setup.py) ... error
  Complete output from command /home/users/augier3pi/tmp/tmp_venv/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/tmp/pip-req-build-_0f8h24y/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-6n4locuo --python-tag cp37:
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-req-build-_0f8h24y/setup.py", line 10, in <module>
      import numpy as np
  ModuleNotFoundError: No module named 'numpy'
  
  ----------------------------------------
  Failed building wheel for irequires
  Running setup.py clean for irequires
  Complete output from command /home/users/augier3pi/tmp/tmp_venv/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/tmp/pip-req-build-_0f8h24y/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" clean --all:
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-req-build-_0f8h24y/setup.py", line 10, in <module>
      import numpy as np
  ModuleNotFoundError: No module named 'numpy'
  
  ----------------------------------------
  Failed cleaning build dir for irequires
Failed to build irequires
Installing collected packages: numpy, irequires
  Running setup.py install for irequires ... done
Successfully installed irequires-0.0.0 numpy-1.16.0

Expected behavior

pip should install numpy before executing python setup.py bdist_wheel so that this simple setup works fine as explained in https://pip.pypa.io/en/latest/reference/pip_install/#installation-order.

Note

Listing packages both in install_requires and setup_requires don’t work well. See https://github.com/pypa/setuptools/issues/209 and https://github.com/pypa/setuptools/issues/391

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:19 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
pradyunsgcommented, Jun 16, 2019

A clarification has been added to the relevant section (see #6604).

Closing this since there isn’t much else actionable here since we mostly just needed a clarification here.

1reaction
jdemeyercommented, Apr 23, 2019

@cjerdonek: The problem is not so much PEP 517, the problem is really bdist_wheel. With PEP 517, bdist_wheel is mandatory and the build fails if the build-and-run-time dependencies are not specified in either pyproject.toml or setup_requires. Without PEP 517, the installation is first done with bdist_wheel, which fails (just like with PEP 517). But in this case, pip falls back to the legacy install mode which does succeed.

So nothing got broken for now (in the sense that packages that used to install still install). But that’s only because pip has a fallback to the old way of installing packages. If that fallback ever gets removed or pyproject.toml becomes mandatory, then this will actually break.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Packaging and distributing projects
It's the command line interface for running various commands that relate to packaging tasks. To get a listing of available commands, run python...
Read more >
Why is python setup.py saying invalid command ' ...
I was using --no-install-recommends in a Docker image (DL3015) and running into this error, I needed to explicitly install python3-wheel .
Read more >
Python setup.py bdist_wheel did not run successfully
To solve the "Python setup.py bdist_wheel did not run successfully" error, run the `pip install cmake` command and make sure you have the ......
Read more >
python packaging: basic setup.py and declarative ... - YouTube
today I go over a basic setup. py for packaging a python package. I then show a few tools you can use to...
Read more >
Python Setup Tools - sdist bdist and wheel and push toPyPI
PIP is the official Python tool to download and install Python distribution packages. It downloads them from the online repository PyPI - we'll ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found