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.
I work on this module as part of my job at Red Hat.
Download
Download tarball releases from:
http://cyberelk.net/tim/data/pycups/
Source Code
Fetch the source like this:
git clone git://git.fedorahosted.org/git/pycups.git
or browse it using gitweb.
New releases are announced at freshmeat.
Bug Reporting
Report bugs using the trac interface.
Discussion
There is no mailing list as such, but if you use Mugshot there is a Fedora Printing group you can join.




May 18th, 2007 at 11:11 am
[...] just heard that pycups is now included in Debian unstable as python-cups. Thanks to Otavio Salvador for packaging and [...]
June 21st, 2007 at 11:45 am
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
June 25th, 2007 at 10:56 am
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’.
September 5th, 2007 at 4:18 pm
[...] 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, [...]
April 28th, 2008 at 12:52 pm
Now at OpenBSD:
http://www.openbsd.org/cgi-bin/cvsweb/ports/print/py-cups/
May 10th, 2008 at 4:46 pm
Now in mandriva too :
http://svn.mandriva.com/cgi-bin/viewvc.cgi/packages/cooker/python-cups/
August 18th, 2008 at 4:40 am
Is there any example code for pycups / python-cups?
August 18th, 2008 at 9:22 am
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’.
August 22nd, 2008 at 7:07 pm
[...] 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 [...]
October 20th, 2008 at 7:17 pm
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.
October 27th, 2008 at 2:22 pm
Hi,
After making the application if I run the example I get: undefined symbol: libiconv. I have libiconv 2.4.0 installed
Any idea?
October 27th, 2008 at 5:56 pm
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).
March 4th, 2009 at 6:29 pm
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))
March 4th, 2009 at 6:41 pm
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.
March 4th, 2009 at 10:30 pm
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?
March 6th, 2009 at 6:24 pm
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?
March 6th, 2009 at 6:41 pm
Robert: use cups.Connection.printFile()/printFiles() to do that.
cups.require(”1.9.39″)
March 6th, 2009 at 7:40 pm
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.