.

cannot import module from qrcode.QRCode in script

<<

nubie

User avatar

Newbie
Newbie

Posts: 34

Joined: Mon Jun 23, 2008 9:03 pm

Post Thu Aug 22, 2013 12:37 am

cannot import module from qrcode.QRCode in script

Hi all,

Hope i can ask some question regarding this issue, i installed python in windows & qrcode(https://pypi.python.org/pypi/qrcode). everything works fine when i test from python interpreter, but when i test using some scripts like this:
  Code:
import qrcode

qr = qrcode.QRCode(version=1,box_size=10, border=4)
qr.add_data("test")
print qr
qr.make(fit=True)
img = qr.make_image()
img.save("C:\\b.png")

And running the script from cmd it show error:
  Code:
Traceback (most recent call last):
  File "qtest.py", line 3, in <module>
    qr = qrcode.QRCode()
AttributeError: 'module' object has no attribute 'QRCode'


I already reinstalled the qrcode(both from source/pip), python, try to repath the site-packages but it's not work either ...

Hope there's someone can enlight me about this issue.


Thank's a lot & sorry,
<<

El33tsamurai

User avatar

Full Member
Full Member

Posts: 219

Joined: Sat Feb 03, 2007 4:01 pm

Post Thu Aug 22, 2013 6:38 am

Re: cannot import module from qrcode.QRCode in script

What have you tried from your research already, such as things found on good? Don't want to share something that you have tried already.
<<

hayabusa

User avatar

Hero Member
Hero Member

Posts: 1662

Joined: Mon Jan 29, 2007 2:59 pm

Post Thu Aug 22, 2013 2:44 pm

Re: cannot import module from qrcode.QRCode in script

Can you provide any further information, regarding HOW you're trying to run the code, outside of the interpreter?

I ran your script, as you've written it, on Python 2.7.1, with no issues, after adding the Imaging and six libraries.
~ hayabusa ~ 

"All men can see these tactics whereby I conquer, but what none can see is the strategy out of which victory is evolved." - Sun Tzu, 'The Art of War'


OSCE, OSCP , GPEN, C|EH
<<

hayabusa

User avatar

Hero Member
Hero Member

Posts: 1662

Joined: Mon Jan 29, 2007 2:59 pm

Post Thu Aug 22, 2013 2:52 pm

Re: cannot import module from qrcode.QRCode in script

Incidentally, RedHat has a bug that looked remarkably similar, as of 2 weeks ago...

https://bugzilla.redhat.com/show_bug.cgi?id=993536

Betting one of your imports is bad, somewhere.
~ hayabusa ~ 

"All men can see these tactics whereby I conquer, but what none can see is the strategy out of which victory is evolved." - Sun Tzu, 'The Art of War'


OSCE, OSCP , GPEN, C|EH
<<

nubie

User avatar

Newbie
Newbie

Posts: 34

Joined: Mon Jun 23, 2008 9:03 pm

Post Thu Aug 22, 2013 8:14 pm

Re: cannot import module from qrcode.QRCode in script

Thank's for your reply,

- what i did is trying to repath the python path & scripts & lib in environment variable because i used this on windows

- i ran my script in command prompt using this way: python script.py, just like that, however if i trying the code in interpreter, it works fine.

I already try this in another pc (windows system too) using python 2.7.2 - it's not work too ... (not yet test in linux system).

Thank's a lot & pardon me .
<<

hayabusa

User avatar

Hero Member
Hero Member

Posts: 1662

Joined: Mon Jan 29, 2007 2:59 pm

Post Fri Aug 23, 2013 1:16 pm

Re: cannot import module from qrcode.QRCode in script

Apologies, but without seeing this one, in action, it's pretty tough to tell you exactly what's wrong.

I can tell you that I duplicated this, ON WINDOWS, and it works fine for me, both from within the interpreter, from "python script.py" and from running the py direct from within windows explorer.

My gut tells me something still isn't quite right with your pathing, etc. I'd also be inclined to think one of your dependency libs that get included is bad, but that shouldn't affect it differently when run from commandline versus interpreter.

Only other possibility I could think of would be, do you have multiple versions of python installed, such that when calling python it's getting a different version than the interpeted version you're running? (Doubtful, as you likely just started the interpreter via the 'python' command, as well, but...)

But again, it works fine for me, regardless of where and how I run it. And again, someone hit a snag in the RedHat world, with that bugzilla entry, which threw the exact same error message as yours.

What happens if you run it using pdb:

python -m pdb script.py

Then you can step through and see if a certain step does anything unexpected. Some commands in pdb (more can be found in online docs):

b: set a breakpoint
c: continue debugging until you hit a breakpoint
s: step through the code
l: list all the variables in the current scope
u: navigate up a stack frame
d: navigate down a stack frame

You can use s, for instance, to step through, and see it load all dependencies, along the way, and try to see if something is behaving differently than expected (granted, could be a long process, but might be helpful)
~ hayabusa ~ 

"All men can see these tactics whereby I conquer, but what none can see is the strategy out of which victory is evolved." - Sun Tzu, 'The Art of War'


OSCE, OSCP , GPEN, C|EH
<<

nubie

User avatar

Newbie
Newbie

Posts: 34

Joined: Mon Jun 23, 2008 9:03 pm

Post Mon Aug 26, 2013 11:04 pm

Re: cannot import module from qrcode.QRCode in script

Hi all, my apologies for my stupidity, the issue already solved, because in folder code already exist file qrcode (built in function, i try to made), whatever its hidden file, so i just move away that file.


Hayabusa, thank's a lot for your tips, it give me an idea for every line running within code.

Thank's a lot & once again, pardon me about this.
<<

hayabusa

User avatar

Hero Member
Hero Member

Posts: 1662

Joined: Mon Jan 29, 2007 2:59 pm

Post Tue Aug 27, 2013 10:06 am

Re: cannot import module from qrcode.QRCode in script

No worries. Glad to have given you some ideas, and glad you figured out your issue.

Good luck with your continued learning, etc!
~ hayabusa ~ 

"All men can see these tactics whereby I conquer, but what none can see is the strategy out of which victory is evolved." - Sun Tzu, 'The Art of War'


OSCE, OSCP , GPEN, C|EH

Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests

.
Powered by phpBB® Forum Software © phpBB Group.
Designed by ST Software