Difference between pip3 and `python3 setup.py install` regarding cmdclass argument

I tried to configure my package so that the script was executed during the installation process. So I inherited from setuptools.command install and created my own ActionOnInstall class to do things when the package is installed. This class is called through the setuptools setup() argument cmdclass , as described here .

A minimal example of such a setup.py file looks like

 from setuptools import find_packages, setup from setuptools.command.install import install class ActionOnInstall(install): def run(self): print("Call install.run(self) works!") install.run(self) setup(name='name', cmdclass={ 'install': ActionOnInstall}) 

Building a package by doing

 pip3 install <path-to-dir-with-setup.py> 

succeeds but does not execute the commands specified in ActionOnInstall.run() . More direct access to this setup.py with

 python3 setup.py install 

executes the commands specified in ActionOnInstall.run() .

Then I found out that I was asking: what is the actual difference between the two approaches for installing the package. I know that, like other posts, pip code makes package installation easier. But how these two approaches relate to the cmdclass setup() argument differently is not explained. So, I would be very happy to hear from you guys.

+8
python installation pip package setuptools
source share
2 answers

pip calls your setup.py but redirects stdout / stderr. To check setup.py in the pip section, write to the file in a fixed location:

 class ActionOnInstall(install): def run(self): print("Call install.run(self) works!", file=open('/tmp/debug.log', 'w')) install.run(self) 

Take a look at /tmp/debug.log after pip install .

+8
source share

pip runs python setup.py install when you install your package - it does not change the way setup.py is configured.

The reason you don't see any output is because, by default, @pd hides all the output from running the setup.py , since most of the information printed when python setup.py install run is not useful to most users.

You can see this hidden output along with everything else pip does by passing the --verbose option to pip install :

 $ pip install --verbose ./foo Processing ./foo Running setup.py (path:/private/var/folders/4d/bt0_xfx56bjfmmt2bv3r5_qh0000gn/T/pip-ti0o0gtu-build/setup.py) egg_info for package from file:///Users/pradyunsg/.venvwrap/venvs/t mp-c0ebb35987c76ad/foo Running command python setup.py egg_info running egg_info creating pip-egg-info/foo.egg-info writing pip-egg-info/foo.egg-info/PKG-INFO writing dependency_links to pip-egg-info/foo.egg-info/dependency_links.txt writing top-level names to pip-egg-info/foo.egg-info/top_level.txt writing manifest file 'pip-egg-info/foo.egg-info/SOURCES.txt' reading manifest file 'pip-egg-info/foo.egg-info/SOURCES.txt' writing manifest file 'pip-egg-info/foo.egg-info/SOURCES.txt' Source in /private/var/folders/4d/bt0_xfx56bjfmmt2bv3r5_qh0000gn/T/pip-ti0o0gtu-build has version 0.0.0, which satisfies requirement foo==0.0.0 from file:///Users/pradyunsg/.ve nvwrap/venvs/tmp-c0ebb35987c76ad/foo Could not parse version from link: file:///Users/pradyunsg/.venvwrap/venvs/tmp-c0ebb35987c76ad/foo Installing collected packages: foo Running setup.py install for foo ... Running command /Users/pradyunsg/.venvwrap/venvs/tmp-c0ebb35987c76ad/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/privat e/var/folders/4d/bt0_xfx56bjfmmt2bv3r5_qh0000gn/T/pip-ti0o0gtu-build/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(comp ile(code, __file__, 'exec'))" install --record /var/folders/4d/bt0_xfx56bjfmmt2bv3r5_qh0000gn/T/pip-cetn8xa9-record/install-record.txt --single-version-externally-managed --compi le --install-headers /Users/pradyunsg/.venvwrap/venvs/tmp-c0ebb35987c76ad/bin/../include/site/python3.6/foo running install Call install.run(self) works! running build running install_egg_info running egg_info creating foo.egg-info writing foo.egg-info/PKG-INFO writing dependency_links to foo.egg-info/dependency_links.txt writing top-level names to foo.egg-info/top_level.txt writing manifest file 'foo.egg-info/SOURCES.txt' reading manifest file 'foo.egg-info/SOURCES.txt' writing manifest file 'foo.egg-info/SOURCES.txt' Copying foo.egg-info to /Users/pradyunsg/.venvwrap/venvs/tmp-c0ebb35987c76ad/lib/python3.6/site-packages/foo-0.0.0-py3.6.egg-info running install_scripts writing list of installed files to '/var/folders/4d/bt0_xfx56bjfmmt2bv3r5_qh0000gn/T/pip-cetn8xa9-record/install-record.txt' done Removing source in /private/var/folders/4d/bt0_xfx56bjfmmt2bv3r5_qh0000gn/T/pip-ti0o0gtu-build Successfully installed foo-0.0.0 Cleaning up... 
+3
source share

All Articles