简体   繁体   中英

Running post install code from PyPi via pip

I am trying to run a block of code after my python package has been downloaded from PyPi.

I've setup a custom cmdclass in my setuptools.setup

from setuptools import find_packages, setup
from setuptools.command.install import install


class CustomInstallCommand(install):
    def run(self):
        print "Here is where I would be running my code..."
        install.run(self)



setup(
  name = 'packagename',
  packages=find_packages(),
  version = '0.1',
  description = '',
  author = '',
  cmdclass={
    'install': CustomInstallCommand,
  },
  author_email = '',
  url = '',
  keywords = [],
  classifiers = [],
)

This works great when I run python setup.py install which outputs my print statement. However, when I build the tar.gz package (using python setup.py sdist ) and try to install via pip ( pip install dist/mypackage-0.1.tar.gz ), the print statement is never printed. I have also tried to upload the built package to PyPi and pip install from there.

I have looked at a similar question asked on stackoverflow but the solution did not work.

pip install does run your custom command, it just hides all standard output from setup.py . To increase verbosity level and see your command output, try running

pip install -v ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM