Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: No module named cups #9

Open
MarcelloNicoletti opened this issue Nov 7, 2012 · 18 comments
Open

ImportError: No module named cups #9

MarcelloNicoletti opened this issue Nov 7, 2012 · 18 comments

Comments

@MarcelloNicoletti
Copy link

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
Copy link
Author

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

@HaTaX2
Copy link

HaTaX2 commented Dec 4, 2012

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
Copy link

branx86 commented Jan 3, 2020

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
Copy link

branx86 commented Jan 3, 2020

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
Copy link

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
Copy link

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
Copy link

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
Copy link

Nothing helped! Same issue with Debian Buster 10

@Gill-Bates
Copy link

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

@abdros
Copy link

abdros commented Jan 6, 2021

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
Copy link

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
Copy link

DXorSX commented Dec 10, 2021

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

@WanderingApps
Copy link

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

@mschindl
Copy link

mschindl commented Aug 30, 2023

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
Copy link

Any idea how to fix it?

@metzenseifner
Copy link

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.

@ersingencturk
Copy link

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

@cshilton
Copy link

If for some reason you still need this script to generate an avahi service description for your printer and you are running into this problem, I solved it as follows on Rocky Linux 9.4:

$ ## Install OS requirements with the os package manager.
$ sudo dnf install python gcc python-devel cups-devel 
$ ## Create a place to work
$ mkdir tmphome && cd tmphome
$ ## Create a temporary place to work
$ git fetch <this repository>
$ ## Create a python environment for the pycups package note well that pycups needs gcc and
$ ## a couple of devel packages. 
$ python3 -m venv venv
$ . venv/bin/activate
$ pip install --upgrade pip
$ pip install pycups
$ python airprint-generate.py ...

This worked for me. All of the above got me to the point where I knew I needed to install pycups into a venv but it wouldn't build/install with just pip install pycups. Reading the pycups documentation - https://github.com/OpenPrinting/pycups/blob/master/README got me the rest of the way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests