ZXing in python FileNotFoundError Problem











up vote
0
down vote

favorite












I have written a simple python code to detect qrCode. Code:



import zxing
reader = zxing.BarCodeReader()
barcode = reader.decode('../images/QR_CODE-easy.png')



print(barcode)



Now, when I run it, I get following error:
FileNotFoundError: [WinError 2] The system cannot find the file specified



I have check this file location is valid by using cv.imread command. Please let me know if someone have sollution of this problem










share|improve this question




























    up vote
    0
    down vote

    favorite












    I have written a simple python code to detect qrCode. Code:



    import zxing
    reader = zxing.BarCodeReader()
    barcode = reader.decode('../images/QR_CODE-easy.png')



    print(barcode)



    Now, when I run it, I get following error:
    FileNotFoundError: [WinError 2] The system cannot find the file specified



    I have check this file location is valid by using cv.imread command. Please let me know if someone have sollution of this problem










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have written a simple python code to detect qrCode. Code:



      import zxing
      reader = zxing.BarCodeReader()
      barcode = reader.decode('../images/QR_CODE-easy.png')



      print(barcode)



      Now, when I run it, I get following error:
      FileNotFoundError: [WinError 2] The system cannot find the file specified



      I have check this file location is valid by using cv.imread command. Please let me know if someone have sollution of this problem










      share|improve this question















      I have written a simple python code to detect qrCode. Code:



      import zxing
      reader = zxing.BarCodeReader()
      barcode = reader.decode('../images/QR_CODE-easy.png')



      print(barcode)



      Now, when I run it, I get following error:
      FileNotFoundError: [WinError 2] The system cannot find the file specified



      I have check this file location is valid by using cv.imread command. Please let me know if someone have sollution of this problem







      python zxing






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 18 at 6:03

























      asked Nov 11 at 11:31









      Hasan Iqbal

      189




      189
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          You appear to be on Windows (as the error code suggests), which uses the backslash for file paths.



          It's not good practice as it won't be widely compatible, but if you're in a hurry and know you won't want to use the code on Mac or Linux, you can use double backslashes:



          reader.decode('..\images\QR_CODE-easy.png')



          Otherwise you should use os.path.join or pathlib (assuming your using Python 3)



          import os.path
          qr_file = os.path.join("..", "images", "QR_CODE-easy.png")



          Or



          from pathlib import Path
          qr_file = Path("../images/QR_CODE-easy.png")



          There are further details of a few options here:



          https://medium.com/@ageitgey/python-3-quick-tip-the-easy-way-to-deal-with-file-paths-on-windows-mac-and-linux-11a072b58d5f



          Edit: it is also worth confirming that your relative path is indeed correct when starting in your current working directory. You can check the current working directory with: cwd = os.getcwd() . You may want to try an absolute path to your file too, just to confirm whether it works with that first.



          More details on cwd here: https://stackoverflow.com/a/5137509/142780






          share|improve this answer























          • I did all the remedies you mentioned, but the same problem persists. Its really frustrating. I think zxing don't work on python3
            – Hasan Iqbal
            Nov 16 at 8:31












          • Sorry to hear that. According to the README in the repo, it is compatible with Python 3: github.com/dlenski/python-zxing/blob/master/README.md
            – Neil
            Nov 17 at 10:43










          • I've added a point about confirming your current working directory and suggest trying an absolute path just to be 100% sure it's not a mix up with the relative path
            – Neil
            Nov 17 at 10:44











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248286%2fzxing-in-python-filenotfounderror-problem%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          You appear to be on Windows (as the error code suggests), which uses the backslash for file paths.



          It's not good practice as it won't be widely compatible, but if you're in a hurry and know you won't want to use the code on Mac or Linux, you can use double backslashes:



          reader.decode('..\images\QR_CODE-easy.png')



          Otherwise you should use os.path.join or pathlib (assuming your using Python 3)



          import os.path
          qr_file = os.path.join("..", "images", "QR_CODE-easy.png")



          Or



          from pathlib import Path
          qr_file = Path("../images/QR_CODE-easy.png")



          There are further details of a few options here:



          https://medium.com/@ageitgey/python-3-quick-tip-the-easy-way-to-deal-with-file-paths-on-windows-mac-and-linux-11a072b58d5f



          Edit: it is also worth confirming that your relative path is indeed correct when starting in your current working directory. You can check the current working directory with: cwd = os.getcwd() . You may want to try an absolute path to your file too, just to confirm whether it works with that first.



          More details on cwd here: https://stackoverflow.com/a/5137509/142780






          share|improve this answer























          • I did all the remedies you mentioned, but the same problem persists. Its really frustrating. I think zxing don't work on python3
            – Hasan Iqbal
            Nov 16 at 8:31












          • Sorry to hear that. According to the README in the repo, it is compatible with Python 3: github.com/dlenski/python-zxing/blob/master/README.md
            – Neil
            Nov 17 at 10:43










          • I've added a point about confirming your current working directory and suggest trying an absolute path just to be 100% sure it's not a mix up with the relative path
            – Neil
            Nov 17 at 10:44















          up vote
          0
          down vote













          You appear to be on Windows (as the error code suggests), which uses the backslash for file paths.



          It's not good practice as it won't be widely compatible, but if you're in a hurry and know you won't want to use the code on Mac or Linux, you can use double backslashes:



          reader.decode('..\images\QR_CODE-easy.png')



          Otherwise you should use os.path.join or pathlib (assuming your using Python 3)



          import os.path
          qr_file = os.path.join("..", "images", "QR_CODE-easy.png")



          Or



          from pathlib import Path
          qr_file = Path("../images/QR_CODE-easy.png")



          There are further details of a few options here:



          https://medium.com/@ageitgey/python-3-quick-tip-the-easy-way-to-deal-with-file-paths-on-windows-mac-and-linux-11a072b58d5f



          Edit: it is also worth confirming that your relative path is indeed correct when starting in your current working directory. You can check the current working directory with: cwd = os.getcwd() . You may want to try an absolute path to your file too, just to confirm whether it works with that first.



          More details on cwd here: https://stackoverflow.com/a/5137509/142780






          share|improve this answer























          • I did all the remedies you mentioned, but the same problem persists. Its really frustrating. I think zxing don't work on python3
            – Hasan Iqbal
            Nov 16 at 8:31












          • Sorry to hear that. According to the README in the repo, it is compatible with Python 3: github.com/dlenski/python-zxing/blob/master/README.md
            – Neil
            Nov 17 at 10:43










          • I've added a point about confirming your current working directory and suggest trying an absolute path just to be 100% sure it's not a mix up with the relative path
            – Neil
            Nov 17 at 10:44













          up vote
          0
          down vote










          up vote
          0
          down vote









          You appear to be on Windows (as the error code suggests), which uses the backslash for file paths.



          It's not good practice as it won't be widely compatible, but if you're in a hurry and know you won't want to use the code on Mac or Linux, you can use double backslashes:



          reader.decode('..\images\QR_CODE-easy.png')



          Otherwise you should use os.path.join or pathlib (assuming your using Python 3)



          import os.path
          qr_file = os.path.join("..", "images", "QR_CODE-easy.png")



          Or



          from pathlib import Path
          qr_file = Path("../images/QR_CODE-easy.png")



          There are further details of a few options here:



          https://medium.com/@ageitgey/python-3-quick-tip-the-easy-way-to-deal-with-file-paths-on-windows-mac-and-linux-11a072b58d5f



          Edit: it is also worth confirming that your relative path is indeed correct when starting in your current working directory. You can check the current working directory with: cwd = os.getcwd() . You may want to try an absolute path to your file too, just to confirm whether it works with that first.



          More details on cwd here: https://stackoverflow.com/a/5137509/142780






          share|improve this answer














          You appear to be on Windows (as the error code suggests), which uses the backslash for file paths.



          It's not good practice as it won't be widely compatible, but if you're in a hurry and know you won't want to use the code on Mac or Linux, you can use double backslashes:



          reader.decode('..\images\QR_CODE-easy.png')



          Otherwise you should use os.path.join or pathlib (assuming your using Python 3)



          import os.path
          qr_file = os.path.join("..", "images", "QR_CODE-easy.png")



          Or



          from pathlib import Path
          qr_file = Path("../images/QR_CODE-easy.png")



          There are further details of a few options here:



          https://medium.com/@ageitgey/python-3-quick-tip-the-easy-way-to-deal-with-file-paths-on-windows-mac-and-linux-11a072b58d5f



          Edit: it is also worth confirming that your relative path is indeed correct when starting in your current working directory. You can check the current working directory with: cwd = os.getcwd() . You may want to try an absolute path to your file too, just to confirm whether it works with that first.



          More details on cwd here: https://stackoverflow.com/a/5137509/142780







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 17 at 10:41

























          answered Nov 11 at 12:26









          Neil

          3971320




          3971320












          • I did all the remedies you mentioned, but the same problem persists. Its really frustrating. I think zxing don't work on python3
            – Hasan Iqbal
            Nov 16 at 8:31












          • Sorry to hear that. According to the README in the repo, it is compatible with Python 3: github.com/dlenski/python-zxing/blob/master/README.md
            – Neil
            Nov 17 at 10:43










          • I've added a point about confirming your current working directory and suggest trying an absolute path just to be 100% sure it's not a mix up with the relative path
            – Neil
            Nov 17 at 10:44


















          • I did all the remedies you mentioned, but the same problem persists. Its really frustrating. I think zxing don't work on python3
            – Hasan Iqbal
            Nov 16 at 8:31












          • Sorry to hear that. According to the README in the repo, it is compatible with Python 3: github.com/dlenski/python-zxing/blob/master/README.md
            – Neil
            Nov 17 at 10:43










          • I've added a point about confirming your current working directory and suggest trying an absolute path just to be 100% sure it's not a mix up with the relative path
            – Neil
            Nov 17 at 10:44
















          I did all the remedies you mentioned, but the same problem persists. Its really frustrating. I think zxing don't work on python3
          – Hasan Iqbal
          Nov 16 at 8:31






          I did all the remedies you mentioned, but the same problem persists. Its really frustrating. I think zxing don't work on python3
          – Hasan Iqbal
          Nov 16 at 8:31














          Sorry to hear that. According to the README in the repo, it is compatible with Python 3: github.com/dlenski/python-zxing/blob/master/README.md
          – Neil
          Nov 17 at 10:43




          Sorry to hear that. According to the README in the repo, it is compatible with Python 3: github.com/dlenski/python-zxing/blob/master/README.md
          – Neil
          Nov 17 at 10:43












          I've added a point about confirming your current working directory and suggest trying an absolute path just to be 100% sure it's not a mix up with the relative path
          – Neil
          Nov 17 at 10:44




          I've added a point about confirming your current working directory and suggest trying an absolute path just to be 100% sure it's not a mix up with the relative path
          – Neil
          Nov 17 at 10:44


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248286%2fzxing-in-python-filenotfounderror-problem%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Bressuire

          Vorschmack

          Quarantine