How can I add post-install scripts to easy_install / setuptools / distutils?

I would like to be able to add a hook to my that will be run post-install (either when easy_install'ing or when doing python install).

In my project, PySmell, I have some support files for Vim and Emacs. When a user installs PySmell the usual way, these files get copied in the actual egg, and the user has to fish them out and place them in his .vim or .emacs directories. What I want is either asking the user, post-installation, where would he like these files copied, or even just a message printing the location of the files and what should he do with them.

What is the best way to do this?


My looks like so:

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from setuptools import setup

version = __import__('pysmell.pysmell').pysmell.__version__

    version = version,
    description = 'An autocompletion library for Python',
    author = 'Orestis Markou',
    author_email = '',
    packages = ['pysmell'],
    entry_points = {
        'console_scripts': [ 'pysmell = pysmell.pysmell:main' ]
    data_files = [
        ('vim', ['pysmell.vim']),
        ('emacs', ['pysmell.el']),
    include_package_data = True,
    keywords = 'vim autocomplete',
    url = '',
    long_description =
PySmell is a python IDE completion helper. 

It tries to statically analyze Python source code, without executing it,
and generates information about a project's structure that IDE tools can

The first target is Vim, because that's what I'm using and because its
completion mechanism is very straightforward, but it's not limited to it.
    classifiers = [
        'Development Status :: 5 - Production/Stable',
        'Environment :: Console',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: BSD License',
        'Operating System :: OS Independent',
        'Programming Language :: Python',
        'Topic :: Software Development',
        'Topic :: Utilities',
        'Topic :: Text Editors',



Here's a stub which demonstrates the python install:

from setuptools.command.install import install as _install

class install(_install):
    def run(self):
        print post_install_message

    cmdclass={'install': install},

No luck with the easy_install route yet.

Asked by: Steven391 | Posted: 27-01-2022

Answer 1

It depends on how the user installs your package. If the user actually runs " install", it's fairly easy: Just add another subcommand to the install command (say, install_vim), whose run() method will copy the files you want in the places where you want them. You can add your subcommand to install.sub_commands, and pass the command into setup().

If you want a post-install script in a binary, it depends on the type of binary you are creating. For example, bdist_rpm, bdist_wininst, and bdist_msi have support for post-install scripts, because the underlying packing formats support post-install scripts.

bdist_egg doesn't support a post-install mechanism by design:

Answered by: Kellan219 | Posted: 28-02-2022

Answer 2

As a work-around, you could set the zip_ok option to false so that your project is installed as an unzipped directory, then it will be a little easier for your users to find the editor config file.

In distutils2, it will be possible to install things to more directories, including custom directories, and to have pre/post-install/remove hooks.

Answered by: Kellan687 | Posted: 28-02-2022

Similar questions

packaging - using setuptools with post-install and python dependencies

This is somewhat related to this question. Let's say I have a package that I want to deploy via rpm because I need to do some file copying on post-install and I have some non-python dependencies I want to declare. But let's also say I have some python dependencies that are easily available in Py...

linux - Run post-install script in a Python Egg (setuptools)

I have created a little Python egg (with setuptools) that I want to install in other machines of my LAN. I have even setup a server for the eggs and all (and the egg is properly downloaded and installed with easy_install -f http://myserver/eggrepository ) :-) I would like to know if there's a way of running an script (bash or Python) when installing it with easy_install (version 0.6c11 and python2.6). ...

python - Post-install errors while installing pywin32-216 on Windows XP

I'm using the pywin32-216.win32-py2.6.exe package to install pywin32 on Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32. I am seeing the following post install errors. Could someone help me understand what going wrong? Thanks in advance. Copied pythoncom26.dll to C:\WINDOWS\system32\pythoncom26.dll Copied pythoncomloader26.dll to C:\WINDOWS\sys...

Python packaging distribute post-install step

I am packaging a project that uses nltk. When you install nltk with pip, you get core functionalitiy, but not all the modules that come with it. To get those modules, you call nltk's download method. I tried the following, but it doesn't work, saying ImportError: No module named nltk. I assume this is happening because import nltk occurs before nltk is installed by the call to setup(...).

Are all post-install options for python setuptools broken?

I'm trying to package a build of PyQt (installers aren't provided for the configuration I need), but I can't find any packaging configuration that works. The issue is not specific to PyQt though. The problem: In order for the module to work, it needs a file in python's PREFIX directory. I understand that this may be bad form, but in my case there needs to be a qt.conf file there, and there isn't anything much I c...

python - Post-install doesn't work

I'm trying to add a post-install step into the The installation works but the code inside run(self) is never executed. Things I've tried (with no result): Install it using both "pip install (-e) ." and "python (develop)" [and later uninstall it, reinstall it, delete .egg-info folder,...] Variations using: do_egg_install, build, bdist_egg,...

python - Pip Post-install Script Interactive Input?

I'm very new to python packaging, and trying to make a pip compatible setup and post-install script for my package for colleagues. The goal of the post-install script is to create a configuration file that will be customized to the end-user and their system, and while I guess I could just have them run a secondary setup script post installation, it seems to make more sense to me to just have the script and associ...

python - post-install scripts and pip install extras

I'm developing a package which has a few optional dependencies and 'extras'. Goal: I want the following two things to work: Execute my post-install code Allow for 'extras' installation Status: Currently I have been able to: Use python install or python develop to execute post-install ...

Automating post-install of Python dependency from Git using Poetry

I'm using Poetry for Python dependency management, along with PyCrate for ASN.1 encoding/decoding. PyCrate is a dependency pulled from GitHub, and once pulled from GitHub, is installed by running a setup file within the PyCrate directory. python setup.p...

python - pipenv Post-Install Actions

I'm using Python via Pharo/GToolkit's PythonBridge, which uses pipenv under the hood. Things are kicked off via this built-in PythonBridge script ( #!/bin/bash cd "$(dirname "$0")" export PIPENV_VENV_IN_PROJECT=1 pipenv install pipenv ru...

Still can't find your answer? Check out these communities...

PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python