1

Anytime when i just try to call pandas module, i have the error:

    import pandas as pd
ValueError: source code string cannot contain null bytes.

I am using VS Code to edit the code. I am sure the file does not contain null bytes, because I rewrote the code and even this import by itself causes the problem.

I have already tried reinstalling Python and VS Code, and I made sure to choose 'add to path' when reinstalling Python.

How can I fix the problem?

11
  • 1
    I'm willing to bet you're accidentally saving the file as UTF-16, which is covered in this answer on the question I linked. BTW, welcome to Stack Overflow! Check out the tour and How to Ask. In the future, please start with your own research. I found that question by googling "python" plus the error message. Commented May 28, 2022 at 22:58
  • Some text encodings are not permissible for Python source code. It is generally best to use utf-8 text encoding, but most importantly, do not use utf-16 or utf-32 since it will use a lot of null bytes. Check the editor settings to make sure the encoding is suitable. Commented May 28, 2022 at 22:58
  • @wjandrea Nice find - the duplicates I turned up were not as good quality. After the edits, I think this question is a good alias for the canonical. Commented May 28, 2022 at 22:59
  • What file do you mean? Where I write my code? I think that a main problem isnt how i create file. Because i have some old files with complted code and when i just add comman 'import pandas', i get the error 'source code string cannot contain null bytes'. Without command 'import pandas',code works Commented May 28, 2022 at 23:01
  • 1
    @ wjandrea 1 days later i solve this problem. TO be honest i didnt understand how i solved it to the end. But I deleted python again, istalled earlier version and opted for all extra options which installer window sugested to me. Then new varian of configurator(global python) appear in the VS and i chose it. Finally VS is working Commented May 29, 2022 at 15:33

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.