cannot import module from qrcode.QRCode in script

Viewing 7 reply threads
  • Author
    Posts
    • #8557
      nubie
      Participant

      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:


      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:


      Traceback (most recent call last):
      File "qtest.py", line 3, in
      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,

    • #53420
      El33tsamurai
      Participant

      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.

    • #53421
      hayabusa
      Participant

      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.

    • #53422
      hayabusa
      Participant

      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.

    • #53423
      nubie
      Participant

      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 .

    • #53424
      hayabusa
      Participant

      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)

    • #53425
      nubie
      Participant

      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.

    • #53426
      hayabusa
      Participant

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

      Good luck with your continued learning, etc!

Viewing 7 reply threads
  • You must be logged in to reply to this topic.

Copyright ©2020 Caendra, Inc.

Contact Us

Thoughts, suggestions, issues? Send us an email, and we'll get back to you.

Sending

Sign in with Caendra

Forgot password?Sign up

Forgot your details?