2

I want to use python code to print to my printer. I installed all the required module but it's not running. The error I got is

Traceback (most recent call last):
  File "/home/pi/Thesis/print_usingcups.py", line 2, in <module>
    conn = cups.Connection()
AttributeError: module 'cups' has no attribute 'Connection'

I got the code from the internet here's the code

import cups
conn = cups.Connection()
printers = conn.getPrinters ()
for printer in printers:
print (printer, printers[printer]["device-uri"])

my expected output is like this EPSON_LX-300 usb://EPSON/LX-300+?serial=L010209081 RICOH_Aficio_SP_100 usb://RICOH/ Aficio?serial=T382M977983 but I received an error.

Klaus D.
  • 13,874
  • 5
  • 41
  • 48
tin tinie
  • 63
  • 1
  • 8
  • 1
    Please show us the full error traceback! – Klaus D. Nov 06 '19 at 07:05
  • 1
    Hi sir, I edited the post and put the full error traceback. – tin tinie Nov 06 '19 at 07:09
  • Now, in the folder you run your code from, open an interactive interpreted by running just `python`, and on the `>>>` prompt run `import cups`, then `cups`! What's the output? – Klaus D. Nov 06 '19 at 07:11
  • Hi sir, it's okay now. Thank you so much! I think i installed an outdated version of cups, it's version is 0.0.6 while the pycups is 1.9.74. I uninstalled the cups and reinstall pycups. – tin tinie Nov 06 '19 at 07:14

2 Answers2

6

you wouldn't have installed cups instead of pycups?

suggestion:

pip uninstall cups
pip install pycups

and try again

studioj
  • 1,300
  • 17
  • 32
  • I got it now sir, thanks. I installed the cups module, I thinks it's outdated or something. Instead of using pycups as a module my code used cups which is an outdated version. Thank you so much! – tin tinie Nov 06 '19 at 07:12
1

Attempting to run pip install pycups results in the error below:

Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-g7Dc7A/pycups/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-4JsSZe/install-record.txt --single-version-externally-managed --compile --user --prefix=" failed with error code 1 in /tmp/pip-install-g7Dc7A/pycups/

Running pip3 install pycups IS successful; however I continue to get "no module named cups". I will continue to investigate and post a solution if I find one.

Mike
  • 43
  • 8
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/30934401) – iwrestledthebeartwice Feb 02 '22 at 09:58