tjfontaine / airprint-generate

Automatically generate AirPrint Avahi service files for CUPS printers
http://www.atxconsulting.com/blog/tjfontaine/2010/11/21/automatically-generate-airprint-avahi-service-files-cups-printers
400 stars 119 forks source link

ImportError: No module named cups #9

Open MarcelloNicoletti opened 11 years ago

MarcelloNicoletti commented 11 years ago

import cups, os, optparse, re, urlparse ImportError: No module named cups I get this when I run this. I am running a RPi and it may be an issue with how the RPi package unpacked.

MarcelloNicoletti commented 11 years ago

ran sudo apt-get install python-cups that fixed the issue

HaTaX2 commented 11 years ago

Because it's somewhat obsecure I'll add this in here, on CentOS machines to add the needed package run "yum install system-config-printer-libs"

branx86 commented 4 years ago

I have CentOs 8 and have "yum install system-config-printer-libs" installed but still gives ImportError: No module named cups, Is their other depends I'm missing

branx86 commented 4 years ago

Well figured out the above problem by Doing in CentOs 8 " pip2 install cups" and " pip3 install cups" now I have : File "./airprint-generate.py", line 261, in cups.setPasswordCB(getpass) AttributeError: module 'cups' has no attribute 'setPasswordCB'

YahBoiiJose commented 3 years ago

sudo apt-get install python-cups

I ran the apt-get command but it says "unable to locate package". Im running linux mint 20 this worked before on linux mint 19

YahBoiiJose commented 3 years ago

sudo apt-get install python-cups

I ran the apt-get command but it says "unable to locate package". Im running linux mint 20 this worked before on linux mint 19

nvm, i solved it. i just need to hunt down for the deb online since its there's no ubuntu 20.04 version available.

josh64x2 commented 3 years ago

Well figured out the above problem by Doing in CentOs 8 " pip2 install cups" and " pip3 install cups" now I have : File "./airprint-generate.py", line 261, in cups.setPasswordCB(getpass) AttributeError: module 'cups' has no attribute 'setPasswordCB'

@branx86 the package name in pip is actually pycups and not cups.

Gill-Bates commented 3 years ago

Nothing helped! Same issue with Debian Buster 10

Gill-Bates commented 3 years ago

apt install python3-cups has solved my issue under Debian 10 Buster

abdros commented 3 years ago

I am running Centos 7.9.2009. I have also come to the 'setPasswordCB' error. I have installed:

python34-cups-1.9.74-4.el7.x86_64 python36-cups-1.9.74-4.el7.x86_64 python-cups-1.9.63-6.el7.x86_64

Anyone has had any luck? Thanks

ersingencturk commented 3 years ago

because the stupid python language has no dependency check or whatsoever. just random bunch of libraries everywhere not compatible with each other or version... update 2021 : the project was updated to python3 so you need to use python3 , second install cups package.. it's not called cups but pycups.. so use pip3 install pycups ... both stupid import cups library has 2 meanings with 2 packages.. !

DXorSX commented 2 years ago

ensure you have only pycups installed. pip3 uninstall cups pip3 install pycups

WanderingApps commented 2 years ago

It does not appear like the cups-pdf or python-cups dependencies are presently available

mschindl commented 10 months ago

I have the same issue, but after the first tips the error message changed. Any idea how to get it running?

# cat /etc/redhat-release Red Hat Enterprise Linux release 9.2 (Plow)

# python --version Python 3.9.16

# pip3 list | grep cups pycups 2.0.1

# sudo ./airprint-generate.py -d /etc/avahi/services/ Traceback (most recent call last): File "/root/./airprint-generate.py", line 279, in <module> apg.generate() File "/root/./airprint-generate.py", line 226, in generate tree.write(f, pretty_print=True, xml_declaration=True, encoding="UTF-8") File "src/lxml/etree.pyx", line 2057, in lxml.etree._ElementTree.write File "src/lxml/serializer.pxi", line 757, in lxml.etree._tofilelike File "src/lxml/etree.pyx", line 318, in lxml.etree._ExceptionContext._raise_if_stored File "src/lxml/serializer.pxi", line 681, in lxml.etree._FilelikeWriter.write TypeError: write() argument must be str, not bytes


Otherwise I tried the containerised method, but no file will be created:

# podman run --rm -it -v $(pwd):/tmp airprint-generate -H 10.1.1.250 -d /root/ I replaced the directory to root, because permission restriction in tmp.

mschindl commented 9 months ago

Any idea how to fix it?

metzenseifner commented 3 months ago

I would recommend ignoring package managers like apt-get and yum. Just use those to install Python 3 unless you want to compile it yourself.

Then do:

python -m env py3
source ./py3/bin/activate
echo $(which python) $(which pip) # Ensure it is the one you just created
pip install pycups # (THIS IS A TRAP! You want the package called pycups and mentioned above)
python airprint-generate.py

Which person thought it was a good idea to name the module "cups" and the package "pycups", while there is also a package called "cups" referring to something else? I ran into https://github.com/tjfontaine/airprint-generate/issues/9#issuecomment-570634614 and solved it by reading https://github.com/tjfontaine/airprint-generate/issues/9#issuecomment-719170249. Thanks everybody.

ersingencturk commented 3 months ago

I would recommend ignoring package managers like apt-get and yum. Just use those to install Python 3 unless you want to compile it yourself.

Then do:

python -m env py3
source ./py3/bin/activate
echo $(which python) $(which pip) # Ensure it is the one you just created
pip install pycups # (THIS IS A TRAP! You want the package called pycups and mentioned above)
python airprint-generate.py

Which person thought it was a good idea to name the module "cups" and the package "pycups", while there is also a package called "cups" referring to something else? I ran into #9 (comment) and solved it by reading #9 (comment). Thanks everybody.

btw, in 2024 you don't need this repository for cups airprint anymore. when you share a printer a cups printer it is airprint ready automatically