pycups

This page is about the Python bindings for the CUPS API, known as pycups. It was written for use with system-config-printer, but can be put to other uses as well.

Download

Download tarball releases from the Python Package Index:
http://pypi.python.org/pypi/pycups

or older releases from:
https://cyberelk.net/tim/data/pycups/

Source Code

The git repository is available at GitHub.

Bug Reporting

Report issues using GitHub.

Comments

86 responses to “pycups”

  1. […] just heard that pycups is now included in Debian unstable as python-cups.  Thanks to Otavio Salvador for packaging and […]

  2. dan avatar
    dan

    Hey Tim,

    trying to use pycups on RHEL5 but can’t even get it to build. I get the following;

    [root@gbwtecsuv1008 pycups-1.9.24]# python setup.py install
    running install
    running build
    running build_ext
    building ‘cups’ extension
    gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector –param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -D_GNU_SOURCE -fPIC -fPIC -I/usr/include/python2.4 -c cupsmodule.c -o build/temp.linux-i686-2.4/cupsmodule.o
    cupsmodule.c: In function ‘cups_require’:
    cupsmodule.c:242: error: ‘VERSION’ undeclared (first use in this function)
    cupsmodule.c:242: error: (Each undeclared identifier is reported only once
    cupsmodule.c:242: error: for each function it appears in.)
    cupsmodule.c:272: error: expected ‘)’ before ‘VERSION’
    error: command ‘gcc’ failed with exit status 1

    Any hints?

    Also, in the setup the package is referred to as “cups” rather than “pycups” which will result in an RPM being produced called cups-1.0 which isn’t what you want (I assume).

    TIA

    Cheers

    Dan

  3. tim avatar

    Dan: run ‘make’ to build pycups — the VERSION macro comes from the environment set up by the Makefile.

    For packaging, I use ‘cups’ for the name because I want to import the extension with ‘import cups’.

  4. […] about to start writing some proper API documentation for pycups, and I’ve been looking around for short-cuts. Seems like epydoc is just what I’m after, […]

  5. ZOG avatar

    Is there any example code for pycups / python-cups?

  6. tim avatar

    Yes, it is used extensively by system-config-printer, in particular the cupshelpers.py file.

    There is also documentation for it included in the pycups source tarball: try ‘make doc’.

  7. […] goodbye to back button woes couldn’t be easier… Just install pycups (from the same developer), pygtk, and the nifty little system-config-printer app found here. There is a little more doc on […]

  8. Ryan avatar
    Ryan

    I went to the trac site to create a bug report, but couldn’t figure out how to create an account there. I eventually found my way here in case others want to submit a bug.

  9. QLand avatar
    QLand

    Hi,

    After making the application if I run the example I get: undefined symbol: libiconv. I have libiconv 2.4.0 installed

    Any idea?

  10. tim avatar

    pycups doesn’t use the symbol ‘libiconv’ directly, however it does use ‘iconv’, ‘iconv_open’, and ‘iconv_close’. These are POSIX.1-2001 functions, so should be provided by your C library (for instance, GNU glibc provides them).

  11. Robert Kajic avatar

    Your source does not build on Mac OS X. Here is a patch.
    Btw, there are C libraries other than glibc…

    Makefile.diff
    14c14
    env LDFLAGS=-liconv CFLAGS=-DVERSION=\\\”$(VERSION)\\\” python setup.py build

    cupsppd.c.diff
    25a26
    > #include
    54a56,65
    > char *
    > strndup(char *src, size_t n)
    > {
    > char *dst = malloc(n);
    >
    > if (!dst)
    > exit(1);
    > return strncpy(dst, src, n);
    > }
    >
    480,481c491
    file);
    if (!fgets(line, linelen, self->file))

  12. tim avatar

    I think your patch has been broken during transit. Please submit patches in unified diff format (i.e. diff -u), preferably from ‘git format-patch’, using the trac interface or normal email.

    However, for this particular case it looks like it needs an autoconf check, which means that it needs to start using autoconf.

  13. Robert Kajic avatar

    I would prefer to email the patch but I can’t seem to find your email.
    However, the modifications I made to the Makefile regarding libiconv seem to have been futile. Python throws the following error when I try cupstree.py
    (right after running make install):

    Traceback (most recent call last):
    File “pycups-1.9.30/cupstree.py”, line 2, in
    import cups
    ImportError: dlopen(/usr/local/lib/python2.6/site-packages/cups.so, 2): Symbol not found: _libiconv
    Referenced from: /usr/local/lib/python2.6/site-packages/cups.so
    Expected in: dynamic lookup

    I noticed that I was able to import cups if I launched python while standing in the source directory where the freshly build cups.so can be found. So I manually copied cups.so to /usr/local/lib/python2.6/site-packages and now I am able to import cups regardless of where it’s started from. Indeed, running cmp on the cups.so that is created by make install and the cups.so that is created by make shows the files are not identical:

    > cmp /usr/local/lib/python2.6/site-packages/cups.so /Users/kajic/stuff/kek/pycups-1.9.30/cups.so
    /usr/local/lib/python2.6/site-packages/cups.so /Users/kajic/stuff/kek/pycups-1.9.30/cups.so differ: char 17, line 1

    How can this be?

  14. Robert Kajic avatar

    I realize I am probably missing out on something but why isn’t it possible to add jobs using pycups? I would very much like to be able to do this and I’ve looked through the pycups documentation but I can’t find an addJob or equivalent method. Right now I am using os.execv and “lp” to add jobs but I would very much like to avoid that. Perhaps there is some other library I could use to add jobs?

  15. tim avatar

    Robert: use cups.Connection.printFile()/printFiles() to do that.

    cups.require(“1.9.39”)

  16. Robert Kajic avatar

    Thanks again! I was using 1.9.30 🙂

    Here are some notes on what I had to do to sucessfully install 1.9.45 (Max OS X 10.5.6):

    In cupsppd.c I had to remove the #ifdef __SVR4 on line 510 (and 528) because otherwise gcc gave the following warning:
    cupsppd.c:557: warning: implicit declaration of function ‘getline’

    and when importing cups in python I got the following error:
    >>> import cups
    Traceback (most recent call last):
    File “”, line 1, in
    ImportError: dlopen(/usr/local/lib/python2.6/site-packages/cups.so, 2): Symbol not found: _getline
    Referenced from: /usr/local/lib/python2.6/site-packages/cups.so
    Expected in: dynamic lookup

    Furthermore I had to add LDFLAGS=-liconv to line 12 in the Makefile. Then after a make and make install I had to manually copy cups.so from the source directory to its install location:
    sudo cp pycups-1.9.45/cups.so /usr/local/lib/python2.6/site-packages/cups.so

    Indeed, as I said in a previous post, pycups-1.9.45/cups.so and pycups-1.9.45/build/lib.macosx-10.3-i386-2.6/cups.so seem to differ:
    > cmp pycups-1.9.45/cups.so pycups-1.9.45/build/lib.macosx-10.3-i386-2.6/cups.so
    pycups-1.9.45/cups.so pycups-1.9.45/build/lib.macosx-10.3-i386-2.6/cups.so differ: char 17, line 1

    I hope this can be of some help to others.

  17. JohnT avatar
    JohnT

    I would very much like to avoid that. Perhaps there is some other library I could use to add jobs?

  18. tim avatar

    JohnT: are you talking about on Mac OS X? You can use libcups directly, of course.

  19. Michael avatar
    Michael

    The package doesn’t build properly on fc10
    Here is the output from build:
    python setup.py build
    running build
    running build_ext
    building ‘cups’ extension
    creating build
    creating build/temp.linux-i686-2.6
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DVERSION=”1.9.54″ -I/usr/local/include/python2.6 -c cupsmodule.c -o build/temp.linux-i686-2.6/cupsmodule.o
    cupsmodule.c: In function ‘do_password_callback’:
    cupsmodule.c:155: error: ‘cups_password_callback’ undeclared (first use in this function)
    cupsmodule.c:155: error: (Each undeclared identifier is reported only once
    cupsmodule.c:155: error: for each function it appears in.)
    cupsmodule.c: In function ‘cups_setPasswordCB’:
    cupsmodule.c:342: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
    cupsmodule.c:342: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
    cupsmodule.c:342: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
    cupsmodule.c:342: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
    cupsmodule.c:343: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
    error: command ‘gcc’ failed with exit status 1
    make: *** [cups.so] Error 1

  20. tim avatar

    Fixed upstream (add “tls->” just before “cups_password_callback” at cupsmodule.c:155).

    However, be aware that Fedora 10 is no longer receiving security updates — you should upgrade to a newer version of Fedora.

  21. Michael avatar
    Michael

    Hm, it fixed the first error.
    The others are still there :
    namely the whole
    cupsmodule.c:342: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
    cupsmodule.c:342: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
    cupsmodule.c:342: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
    cupsmodule.c:342: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
    cupsmodule.c:343: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’

  22. Michael avatar
    Michael

    Could it be due to the fact that I have cups 1.31 and not 1.4 ?

  23. Michael avatar
    Michael

    Ok I removed the 2 lines referring to the cups_password_callback_context and was able to compile.
    Now there is another problem when trying to run some package using pycups (namely cloudprint).
    ImportError: /usr/local/lib/python2.6/site-packages/cups.so: undefined symbol: cupsGetPPD3
    It is most likely due to the fact that I have cups 1.31 .
    Any way to force the build so it uses 1.31 ?

  24. tim avatar

    Both problems also fixed in the git repository now.

  25. Michael avatar
    Michael

    Thanks,
    Actually I fixed them myself in the code and recompiled 🙂
    I also had a problem with getPPD3 and have to comment out the appropriate functions as well.
    Anyway it works fine now with the cloudprint.

  26. Rogier avatar
    Rogier

    I am also getting this ImportError when starting the python cloudprint script:

    ImportError: /usr/local/lib/python2.6/site-packages/cups.so: undefined symbol: cupsGetPPD3

    Can you point me in the direction where to comment out the appropriate functions so this error will not occur?

    My OS is Ubuntu 8.04 server with python 2.6 and pycups-1.9.55 installed.

    Thanks

  27. tim avatar

    Rogier: you need a newer version of cups or else wait for pycups-1.9.56 which will work around compiling against older versions.

  28. macaronij avatar
    macaronij

    very good work, it could be very helpfull to have an intro / tutorial whit the basic
    something very easy just to start using the module

    #Connect to CUPS whit the default user
    printer = cups.Connection()

    #Define the default printer name
    default_printer = printer.getDefault()

    #Print a Test Page in the default printer
    printer.printTestPage(default_printer)

    #Print a file whit the default options
    printer.printFile(default_printer,”PATH/FILE”,”Title”,{})

    perhaps some example adding a printer, etc…

    i know it s very noob but it can save some time to a lot of people, i dind’t find any tutorial on the web and didn t know if this module could do the stuff i need until i build it and ask help(cups)…

  29. tim avatar

    Yes, good idea. Or maybe I should make it a bit more like pysmbc and have the full documentation online.

  30. mrbox avatar

    Great lib! After some problems everything works like a charm 🙂

  31. Gowtham avatar
    Gowtham

    Hi Tim,

    Thanks for releasing this py binding library. Made my development time much shorter and I didn’t have to put in a lot of effort to write using C library.

    I could accomplish most of my tasks using pycups library. However, there is one API component which is available in C library but not exposed through pycups library, i.e cupsAdminExportSamba.

    I managed to write the PyObject method to extend pycups library for this API call. But, the major constraint is that this call relies on cups-windows drivers to be available on the local machine alongside with libcups. Now, I am not sure how this fits into the pycups library when there is an additional dependency. Perhaps, you have better idea.

  32. tim avatar

    It just needs to behave the same as the libcups function would.

  33. Gowtham avatar
    Gowtham

    One (rather ignorant) question, How do I send you a pull request(like github) for you to check the changes I have made?

  34. tim avatar

    Just let me know the URL to your git repository and I can take a look.

  35. tim avatar

    Thanks. One comment:

    +  char str[80];
    [...]
          fgets (str, 79, tf);
    

    That would be better as:

          fgets (str, sizeof (str), tf);
    

    and perhaps a comment explaining what that file is expected to look like and why the last line is relevant in this situation.

    (Note that fgets already leaves space for, and stores, a terminating nul character.)

  36. Gowtham avatar
    Gowtham

    Thanks for looking into it. Took some time to come back to this, blame on holiday time.

    Heres my commit with changes as per your suggestions-
    https://github.com/narisipalli/pycups/commit/38911235208055324299a4df6699672528ffccc6

  37. tim avatar

    Thanks. Some warnings when building though:

    upsconnection.c: In function ‘Connection_adminExportSamba’:
    cupsconnection.c:3808:13: warning: ignoring return value of ‘fgets’, declared with
    attribute warn_unused_result [-Wunused-result]
    

    Should really check this.

    cupsconnection.c:3817:8: warning: attempt to free a non-heap object ‘str’ [enabled by default]
    

    I didn’t spot this when looking through first of all, but str is declared on the stack so we don’t need to free it.

    When I import your git repository it has a separate history of its own instead of branching from mine… isn’t it meant to share a common ancestor?

  38. Gowtham avatar
    Gowtham

    Thanks for pointing out these issues.
    Modified the fgets code to avoid compiler warnings and also removes the new line character that comes along with fgets.

    I cleanup with the commit history to push to github earlier. I shouldn’t have done that. I overwrote my previous commits to keep the index intact. I lost some of the interim commits(No big deal!)
    https://github.com/narisipalli/pycups/commits/

    Heres the full commit of my changes-
    https://github.com/narisipalli/pycups/commit/4a857c31a40222b7c78e732d2a1769348039b06e

  39. tim avatar

    Thanks, merged.

  40. Gowtham avatar
    Gowtham

    Thanks. When are you planning to push the tar of the new version 1.9.58?

  41. tim avatar

    I’ll probably get to it this week.

  42. tim avatar

    macaronij: the new 1.9.58 release is now registered at PyPI and the documentation is there as well. See links in the main page, above.

  43. Ladislav Hagara avatar
    Ladislav Hagara

    $ gpg –verify pycups-1.9.58.tar.bz2.asc
    gpg: Signature made Tue Jul 26 13:28:58 2011 CEST using RSA key ID F4DE942C
    gpg: BAD signature from “Tim Waugh “

  44. Ladislav Hagara avatar
    Ladislav Hagara

    I had to update Makefile for Source Mage GNU/Linux. You changed in this version ln -sf to mv for cups.so, I had to change it back.

    sed -i ‘s:mv build/lib:ln -sf build/lib:’ Makefile

    Source Mage commit:
    http://scmweb.sourcemage.org/gitweb.cgi?p=smgl/grimoire.git;a=commitdiff;h=d831437ebbebfa020aa4176058f8c565e1a41908;hp=f31d661af73c9265c983523514dc615d60eb0e16

  45. tim avatar

    GPG signature fixed: the signature I still had here on disk was the same, most likely a memory issue that was fixed in the last few weeks.

    I’ve applied your other change.

  46. Philippe avatar
    Philippe

    I tried posting a ticket on trac but there’s no registration page ?

    Anyway, requested_attributes doesn’t seem to work in Connection.getJobs(). It will always return an empty dict. It works with getJobAttributes though. Let me know if you need more details.

  47. Philippe avatar
    Philippe

    While I’m at it: your software is awesome 🙂 I added print support with full option handling to my django web app in a day of coding. Thanks a bunch!

  48. tim avatar

    The registration is the Fedora Project registration.

    What version of CUPS are you running? That might very well make the difference…

  49. Philippe avatar
    Philippe

    Sorry I forgot to mention: 1.9.51-0ubuntu2
    If that’s fixed in a newer version sorry for bothering, otherwise I’ll open a ticket when I get back at the office on monday.

  50. tim avatar

    That’s a pycups version number; what about CUPS? pycups just returns whatever CUPS tells it to.

  51. Philippe avatar
    Philippe

    cups is 1.4.4-6ubuntu2.3

    I’m using ubuntu 10.04.3 LTS.

  52. paul avatar
    paul

    I seem to be missing some bits. This is on a FreeBSD 8.2 system with cups 1.5.2 installed. I’ll reinstall it in a minute and see if that clears it up. Not sure about the python bindings for avahi which I guess I also need…

    Running pycups-1.9.61/setup.py -q bdist_egg –dist-dir /tmp/easy_install-QdiX77/pycups-1.9.61/egg-dist-tmp-zYalnU
    cupsmodule.c:23:23: error: cups/cups.h: No such file or directory
    cupsmodule.c:24:27: error: cups/language.h: No such file or directory
    In file included from cupsmodule.c:26:
    cupsmodule.h:25:28: error: cups/adminutil.h: No such file or directory
    cupsmodule.h:53:2: error: #error pycups requires CUPS 1.2.x
    In file included from cupsmodule.c:33:
    cupsconnection.h:24:23: error: cups/http.h: No such file or directory
    In file included from cupsmodule.c:33:
    cupsconnection.h:37: error: expected declaration specifiers or ‘…’ before ‘http_t’

  53. paul avatar
    paul

    I left a comment about building this on FreeBSD: turns out its in the ports collection there.

  54. zac avatar

    Thank you for writing this wonderful module. It defiantly will make my time working with printer abstractions in UNIX much easier for my program.

    Question though: is there any attribute or method to find what is marked as the default printer with? All I could find in the documentation about it is CUPS_PRINTER_DEFAULT, but I’m not sure where this is exposed in the actual printer attribute list.

  55. tim avatar

    cups.Connection.getDests() returns a dict whose values each have an is_default attribute. That will reflect the user’s personal default setting.

    To find out which is the default printer for a given server, examine the ‘printer-type’ attribute in the return value of cups.Connection.getPrinterAttributes(): it is a bitmap, and CUPS_PRINTER_DEFAULT is one of those bits.

  56. Dmitri avatar

    can someone help me out?
    http://forums.gentoo.org/viewtopic-t-931628.html
    I can not figure out how to fix it.
    [code]
    building ‘cups’ extension
    creating build
    creating build/temp.linux-x86_64-2.7
    x86_64-pc-linux-gnu-gcc -pthread -march=core2 -mtune=generic -Os -pipe -msse3 -msse4 -mcx16 -msahf -mpopcnt -DVERSION=”1.9.61″ -fPIC -DVERSION=”1.9.61″ -I/usr/include/python2.7 -c cupsmodule.c -o build/temp.linux-x86_64-2.7/cupsmodule.o
    cupsmodule.c: In function ‘cups_ppdSetConformance’:
    cupsmodule.c:413:3: warning: ‘ppdSetConformance’ is deprecated (declared at /usr/include/cups/ppd.h:414) [-Wdeprecated-declarations]
    cupsmodule.c: In function ‘initcups’:
    cupsmodule.c:853:3: error: ‘CUPS_SERVER_REMOTE_PRINTERS’ undeclared (first use in this function)
    cupsmodule.c:853:3: note: each undeclared identifier is reported only once for each function it appears in
    error: command ‘x86_64-pc-linux-gnu-gcc’ failed with exit status 1
    [/code]

    1. tim avatar

      Which version of cups are you building it against?

  57. Dmitri avatar

    net-print/cups-1.6.0 USE=”X acl dbus filters pam python ssl threads usb -avahi -debug -gnutls -java -kerberos (-selinux) -static-libs -systemd -xinetd -zeroconf”

    1. tim avatar

      There are some fixes since 1.9.61 for CUPS 1.6. I’ll make a new release soon.

  58. Dmitri avatar

    thanks.
    UPD:
    I just updated CUPS from SVN and it did not help any.

    [code]
    emerge -v pycups

    These are the packages that would be merged, in order:

    Calculating dependencies… done!
    [ebuild N ] dev-python/pycups-1.9.61 USE=”-doc -examples” 0 kB

    Total: 1 package (1 new), Size of downloads: 0 kB

    >>> Verifying ebuild manifests

    >>> Emerging (1 of 1) dev-python/pycups-1.9.61
    * pycups-1.9.61.tar.bz2 SHA256 SHA512 WHIRLPOOL size 😉 … [ ok ]
    >>> Unpacking source…
    >>> Unpacking pycups-1.9.61.tar.bz2 to /var/tmp/portage/dev-python/pycups-1.9.61/work
    >>> Source unpacked in /var/tmp/portage/dev-python/pycups-1.9.61/work
    >>> Preparing source in /var/tmp/portage/dev-python/pycups-1.9.61/work/pycups-1.9.61 …
    >>> Source prepared.
    >>> Configuring source in /var/tmp/portage/dev-python/pycups-1.9.61/work/pycups-1.9.61 …
    >>> Source configured.
    >>> Compiling source in /var/tmp/portage/dev-python/pycups-1.9.61/work/pycups-1.9.61 …
    python2.7 setup.py build
    running build
    running build_ext
    building ‘cups’ extension
    creating build
    creating build/temp.linux-x86_64-2.7
    x86_64-pc-linux-gnu-gcc -pthread -march=core2 -mtune=generic -Os -pipe -msse3 -msse4 -mcx16 -msahf -mpopcnt -DVERSION=”1.9.61″ -fPIC -DVERSION=”1.9.61″ -I/usr/include/python2.7 -c cupsmodule.c -o build/temp.linux-x86_64-2.7/cupsmodule.o
    cupsmodule.c: In function ‘cups_ppdSetConformance’:
    cupsmodule.c:413:3: warning: ‘ppdSetConformance’ is deprecated (declared at /usr/include/cups/ppd.h:414) [-Wdeprecated-declarations]
    cupsmodule.c: In function ‘initcups’:
    cupsmodule.c:853:3: error: ‘CUPS_SERVER_REMOTE_PRINTERS’ undeclared (first use in this function)
    cupsmodule.c:853:3: note: each undeclared identifier is reported only once for each function it appears in
    error: command ‘x86_64-pc-linux-gnu-gcc’ failed with exit status 1
    * ERROR: dev-python/pycups-1.9.61 failed (compile phase):
    * Building failed
    *
    * Call stack:
    * ebuild.sh, line 85: Called src_compile
    * environment, line 5288: Called distutils_src_compile
    * environment, line 1296: Called die
    * The specific snippet of code:
    * “$(PYTHON)” “${setup_file#*|}” “${_DISTUTILS_GLOBAL_OPTIONS[@]}” build “$@” || die “Building failed”;
    *
    * If you need support, post the output of `emerge –info ‘=dev-python/pycups-1.9.61’`,
    * the complete build log and the output of `emerge -pqv ‘=dev-python/pycups-1.9.61’`.
    * The complete build log is located at ‘/var/tmp/portage/dev-python/pycups-1.9.61/temp/build.log’.
    * The ebuild environment file is located at ‘/var/tmp/portage/dev-python/pycups-1.9.61/temp/environment’.
    * Working directory: ‘/var/tmp/portage/dev-python/pycups-1.9.61/work/pycups-1.9.61’
    * S: ‘/var/tmp/portage/dev-python/pycups-1.9.61/work/pycups-1.9.61’

    >>> Failed to emerge dev-python/pycups-1.9.61, Log file:

    >>> ‘/var/tmp/portage/dev-python/pycups-1.9.61/temp/build.log’

    * Messages for package dev-python/pycups-1.9.61:

    * ERROR: dev-python/pycups-1.9.61 failed (compile phase):
    * Building failed
    *
    * Call stack:
    * ebuild.sh, line 85: Called src_compile
    * environment, line 5288: Called distutils_src_compile
    * environment, line 1296: Called die
    * The specific snippet of code:
    * “$(PYTHON)” “${setup_file#*|}” “${_DISTUTILS_GLOBAL_OPTIONS[@]}” build “$@” || die “Building failed”;
    *
    * If you need support, post the output of `emerge –info ‘=dev-python/pycups-1.9.61’`,
    * the complete build log and the output of `emerge -pqv ‘=dev-python/pycups-1.9.61’`.
    * The complete build log is located at ‘/var/tmp/portage/dev-python/pycups-1.9.61/temp/build.log’.
    * The ebuild environment file is located at ‘/var/tmp/portage/dev-python/pycups-1.9.61/temp/environment’.
    * Working directory: ‘/var/tmp/portage/dev-python/pycups-1.9.61/work/pycups-1.9.61’
    * S: ‘/var/tmp/portage/dev-python/pycups-1.9.61/work/pycups-1.9.61’

    [/code]

    1. tim avatar

      You’ll need a newer version of pycups. I haven’t released one yet, but the git repository has the fixes.

  59. Dmitri avatar

    pycups successfully compiled with cups-1.5.3

  60. […] why not just use pycups or pkipplib? pycups is tightly coupled with CUPS itself. You need to have CUPS binaries installed […]

  61. […] enable Airprint, we will use the airprint-generate.py. For this, we also need the pycups library. I have used version 1.9.62 but I guess that newer version will also […]

  62. Gavin Jackson avatar

    Hello, I get the following errors when building againt cups-devel-1.4.2-67.el6.x86_64 on Red Hat Enterprise Linux Server release 6.6 (Santiago) python 3.4.2.

    Cheers,
    Gav


    cupsmodule.c:1315: error: ‘IPP_OP_RELEASE_HELD_NEW_JOBS’ undeclared (first use in this function)

    cupsmodule.c:1316: error: ‘IPP_OP_DEACTIVATE_PRINTER’ undeclared (first use in this function)

    1. Peter avatar
      Peter

      Hi, I’ve been installing cups with pycups without an issue for a couple months, but since early December, we’ve been running into this issue when we perform the command: sudo pip install pycups.

      A lot of errors appear similar to this:

      cupsmodule.c:1282:3: error: ‘IPP_OP_PRINT_URI’ undeclared
      cupsmodule.c:1284:3: error: ‘IPP_OP_CREATE_JOB’ undeclared

      etc. etc. The errors seem to all have to do with IPP_OP_something something.

      Any assistance would be greatly appreciated.

      1. Tim avatar

        These ‘IPP_* undeclared’ errors are fixed in pycups-1.9.71.

        1. Gavin Jackson avatar

          Hi Tim,

          Thanks for that – any ideas when we will see a 1.9.71 release on pypi?

          Cheers,
          Gav

          1. Tim avatar

            Thanks for reminding me. I’ve released 1.9.71 today.

        2. Gavin Jackson avatar

          Thanks Tim! I’ll update when I get back to work on Monday!

          1. Gavin Jackson avatar

            Hey Tim,

            Sorry still getting IPP_ undeclared problems with pycups 1.7.1 (same config as above)

            Running setup.py bdist_wheel for pycups
            Destination directory: /home/gavinj/wheelhouse
            Complete output from command /home/gavinj/pyvenv_libtest/bin/python3 -c “import setuptools;__file__=’/home/gavinj/pyvenv_libtest/build/pycups/setup.py’;exec(compile(open(__file__).read().replace(‘\r\n’, ‘\n’), __file__, ‘exec’))” bdist_wheel -d /home/gavinj/wheelhouse:
            running bdist_wheel

            running build

            running build_ext

            building ‘cups’ extension

            creating build

            creating build/temp.linux-x86_64-3.4

            gcc -pthread -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -I/usr/include/expat21 -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DVERSION=”1.9.71″ -I/home/gavinj/pyvenv_libtest/include -I/usr/include/python3.4m -c cupsmodule.c -o build/temp.linux-x86_64-3.4/cupsmodule.o

            cupsmodule.c: In function ‘PyInit_cups’:

            cupsmodule.c:1350: error: ‘IPP_UPGRADE_REQUIRED’ undeclared (first use in this function)

            cupsmodule.c:1350: error: (Each undeclared identifier is reported only once

            cupsmodule.c:1350: error: for each function it appears in.)

            cupsmodule.c:1446: error: ‘IPP_CANCEL_DOCUMENT’ undeclared (first use in this function)

            cupsmodule.c:1447: error: ‘IPP_GET_DOCUMENT_ATTRIBUTES’ undeclared (first use in this function)

            cupsmodule.c:1448: error: ‘IPP_GET_DOCUMENTS’ undeclared (first use in this function)

            cupsmodule.c:1449: error: ‘IPP_DELETE_DOCUMENT’ undeclared (first use in this function)

            cupsmodule.c:1450: error: ‘IPP_SET_DOCUMENT_ATTRIBUTES’ undeclared (first use in this function)

            cupsmodule.c:1451: error: ‘IPP_CANCEL_JOBS’ undeclared (first use in this function)

            cupsmodule.c:1452: error: ‘IPP_CANCEL_MY_JOBS’ undeclared (first use in this function)

            cupsmodule.c:1453: error: ‘IPP_RESUBMIT_JOB’ undeclared (first use in this function)

            cupsmodule.c:1454: error: ‘IPP_CLOSE_JOB’ undeclared (first use in this function)

            cupsmodule.c:1455: error: ‘IPP_IDENTIFY_PRINTER’ undeclared (first use in this function)

            error: command ‘gcc’ failed with exit status 1

          2. Tim avatar

            Oops, sorry. I released 1.9.72 yesterday to fix this.

  63. Steve avatar
    Steve

    Seeing a massive number of the “undeclared (first use in this function)” errors when building on:
    Red Hat Enterprise Linux Server release 7.1 (Maipo)
    cups-libs-1.6.3-17.el7_1.1.x86_64
    cups-devel-1.6.3-17.el7_1.1.x86_64
    python-2.7.5-18.el7_1.1.x86_64
    python-devel-2.7.5-18.el7_1.1.x86_64

    Sample:
    $ python setup.py build
    running build
    running build_ext
    building ‘cups’ extension
    creating build
    creating build/temp.linux-x86_64-2.7
    gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong –param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong –param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DVERSION=”1.9.72″ -I/usr/include/python2.7 -c cupsmodule.c -o build/temp.linux-x86_64-2.7/cupsmodule.o
    cupsmodule.c: In function ‘cups_ppdSetConformance’:
    cupsmodule.c:600:3: warning: ‘ppdSetConformance’ is deprecated (declared at /usr/include/cups/ppd.h:414) [-Wdeprecated-declarations]
    ppdSetConformance (level);
    ^
    cupsmodule.c: In function ‘initcups’:
    cupsmodule.c:1181:22: error: ‘HTTP_STATUS_ERROR’ undeclared (first use in this function)
    INT_CONSTANT_ALIAS(HTTP_STATUS_##name, “HTTP_”#name)
    ^
    cupsmodule.c:1116:51: note: in definition of macro ‘INT_CONSTANT_ALIAS’
    PyDict_SetItemString (d, #name, PyInt_FromLong (name)); \
    ^
    cupsmodule.c:1187:3: note: in expansion of macro ‘INT_HTTP_STATUS_CONSTANT’
    INT_HTTP_STATUS_CONSTANT (ERROR);
    ^
    cupsmodule.c:1181:22: note: each undeclared identifier is reported only once for each function it appears in
    INT_CONSTANT_ALIAS(HTTP_STATUS_##name, “HTTP_”#name)
    ^
    cupsmodule.c:1116:51: note: in definition of macro ‘INT_CONSTANT_ALIAS’
    PyDict_SetItemString (d, #name, PyInt_FromLong (name)); \
    ^

    1. Tim avatar

      Should be fixed now in master.

      1. Steve avatar
        Steve

        Thank you, built fine. Very much appreciate your time to fix.

  64. keshav avatar
    keshav

    Thank you for pycups. I’ve had a good time with it for the past few days. I am working on a small project that archives local print jobs for retrieval and analysis. To this end, I found a Redhat email post by you on “CUPS Configuration: Get-Notifications”.

    Could you please take some time to elaborate on `Connection.createSubscription()` method?

    Specifically, what do the parameters `uri`, `recipient_uri`, and `events` mean?

    1. Tim Waugh avatar

      Hi,

      As pycups is simply a wrapper around libcups, the best thing to look for is the CUPS documentation.

      If you can’t find what you need there, as CUPS is an implementation of IPP the next step is the IPP specification.

      Here’s a start for CUPS:
      http://www.cups.org/documentation.php/spec-ipp.html#CREATE_PRINTER_SUBSCRIPTION

  65. Gael C avatar
    Gael C

    Hi Tim,

    Thank you for pycups. I use it in several software and it’s work perfectly.
    I have a question. Is there a way to print several file if I want to specify different option (to change paper bac for example) for each file ?

    Perhaps cups.Connection.printFiles function reply to my question but how to specify options for 1rst document, options for second document, …

    Thank’s by advance for your answer.
    Have a good day.

    Gael

    1. Tim Waugh avatar

      No, I think you’d have to issue separate requests for that.

  66. beanpow avatar
    beanpow

    Hi Tim,
    thank you for pycups. i want to know how to use pycups,but i can’t open the website of the document?can you help me ?

    1. Tim Waugh avatar

      Unfortunately pythonhosted.org documentation can no longer be uploaded so I’ve removed it.

      To see the documentation, run ‘make doc’ once you have unpacked the tar file.

Leave a Reply

Your email address will not be published. Required fields are marked *