2013-04-06 5 views
12

Ich möchte mein Python-Paket" Pip installierbar ". Das Problem besteht darin, dass das Paket über ein Shell-Skript verfügt, das im Shell-Skript des Benutzers init aufgerufen werden muss (z. B. .bashrc).Benutzerdefinierte Aufgabe ausführen, wenn Aufruf `pip installieren`

Aber nach der Installation weiß der Benutzer nicht genau wohin das Skript ging (vermutlich /usr/bin, aber wir können nicht garantieren). Natürlich kann der Benutzer which myscript.sh ausführen und sein Init-Skript manuell bearbeiten.

Aber ich möchte diesen Schritt automatisieren. Ich kann einen neuen Befehl distutils erstellen, aber pip install ruft es nicht auf. Und ich kann distutils.command.install.install verlängern, aber die Installation bricht über pip (obwohl Werke über python setup.py install):

setup.py

from distutils.command.install import install 

class CustomInstall(install): 
def run(self): 
    install.run(self) 
    # custom stuff here 
    do_my_stuff() 

setup(..., cmdclass={'install': CustomInstall}) 

Schale

$ pip install dist/mypackage.tar.gz 
Unpacking ./dist/mypackage.tar.gz 
    Running setup.py egg_info for package from file:///path/to/mypackage/dist/mypackage.tar.gz 

Installing collected packages: mypackage 
    Running setup.py install for mypackage 
    usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] 
     or: -c --help [cmd1 cmd2 ...] 
     or: -c --help-commands 
     or: -c cmd --help 

    error: option --single-version-externally-managed not recognized 
    Complete output from command /path/to/.virtualenvs/myvirtualenv/bin/python -c "import setuptools;__file__='/tmp/pip-OFjrqU-build/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-s4Yo4d-record/install-record.txt --single-version-externally-managed --install-headers /path/to/.virtualenvs/myvirtualenv/include/site/python2.7: 
    usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] 
     or: -c --help [cmd1 cmd2 ...] 
     or: -c --help-commands 
     or: -c cmd --help 

error: option --single-version-externally-managed not recognized 

---------------------------------------- 
Command /path/to/.virtualenvs/myvirtualenv/bin/python -c "import setuptools;__file__='/tmp/pip-OFjrqU-build/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-s4Yo4d-record/install-record.txt --single-version-externally-managed --install-headers /path/to/.virtualenvs/myvirtualenv/include/site/python2.7 failed with error code 1 in /tmp/pip-OFjrqU-build 
Storing complete log in /path/to/myhome/.pip/pip.log 

Was ist der beste aproach eine benutzerdefinierte Aufgabe nach der Installation eines Pakets über pip ausführen?

+1

Können Sie mit 'from setuptools.command.install import install' versuchen, anstatt' distutils' zu verwenden? –

+1

@Alok, es hat funktioniert! Bitte antworte, damit ich es annehmen kann. :) – borges

+0

Fertig. Froh, dass es funktioniert hat. –

Antwort

11

Konnten Sie mit from setuptools.command.install import install anstelle von distutils versuchen?

+0

Danke, das hat mir wirklich geholfen. Ich hatte gefolgt (https://stackoverflow.com/questions/17806485/execute-a-python-script-post-install-using-distutils-setuptools) und erhielt das gleiche Problem, dokumentiert in (http: // blog. diffbrent.com/correctly-adding-nltk-to-your-python-package-using-setup-py-post-install-commands/) und gab Ihnen Requisiten –

+5

Ich bekomme das gleiche Problem wie [hier] (http: //stackoverflow.com/questions/19569557/pip-not-picking-up-a-custom-install-cmdclass?lq=1) - Ich bekomme das benutzerdefinierte Verhalten beim Ausführen von 'python setup.py install', aber nicht, wenn ich run 'pip install '. Irgendwelche Gedanken? – scubbo

+5

Ich habe das gleiche Problem. '' 'pip install -e .''' führt die Befehlsklasse aus und dann wird es ausgeführt, wenn ich bdist_wheel mache, aber während der Pip-Installation passiert nichts. – bjorns