Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is setup.py executed twice by pip?

Consider a very simple setup.py:

from setuptools import setup, find_packages

print('WAAAAAAAAA') # executed twice!

setup(
    name="foo",
    version="190425",
    description="bar",
    author="Developers",
    author_email="[email protected]",
    install_requires=["pyzmq", "pybullet"],
    packages=find_packages(),
)

Why exactly is the module loaded twice when running pip install . -v and what can I do to guard the code so it runs only once per invocation of pip, just like setup()?

like image 796
oarfish Avatar asked Oct 31 '25 09:10

oarfish


1 Answers

The answer turns out to be that pip install . executes setup.py twice (the verbose output actually says it) since it executes the egg_info subcommand and then the install subcommand.

A possible solution is to check if sys.argv[1] == 'install' and only then execute whatever is desired.

like image 100
oarfish Avatar answered Nov 02 '25 23:11

oarfish