Mystery ValueError

New install of PyCharm, never installed before, I let it do it’s default setup, and to test I ran this:

print("I love pizza")

and got this:

  Traceback (most recent call last):
    File "C:\Users\joel\AppData\Local\Programs\Python\Python310\lib\site.py", line 186, in addpackage
      exec(line)
    File "<string>", line 1, in <module>
  ValueError: source code string cannot contain null bytes

Remainder of file ignored
I love pizza

Process finished with exit code 0

I’ve completely removed and reinstalled 3 times with the same result.

I’m on a fully updated Windows 10 x64 laptop. Any suggestions how to fix?

Looks like you have a bad .pth file - these are used to specify additional search paths for packages, and may contain code. Is there any more console output, it should tell you the relevant file and path? If not, you can also try running python -v, which makes it print all the .pth files as they’re loaded.

1 Like

Further testing showed a few files that were affected in some way, but couldn’t find anything wrong with the lines and code that were referenced. But then I don’t know 100% what to look for, although nothing looked out of place to my knowledge.

I just won’t use PyCharm. There are other ways to run code. :slight_smile:

Hi Joel,

If you google for the error message, you will see that this error can

occur using many different IDEs, or even no IDE at all, just the vanilla

Python interpreter. One common cause is that somewhere you have a file

which is saved as UTF-16, or somehow contains binary NUL bytes.

If that file was installed by PyCharm, it is a bug in PyCharm and they

will probably fix it once they become aware of it.

If that file was installed by you, then changing to a different IDE

won’t stop the error. You will need to track down the offending file and

fix it, or remove it.

One way this can happen is if you open the files in Notepad, and then

save them, if Notepad is set to use UTF-16 or UTF-32. Make sure you only

use UTF-8 for your Python files.

Hi Steven,

Yes, I have Notepad set to UTF-8, so that’s all good.

I’m thinking it’s a PyCharm bug. After installation I immediately typed the print command I mentioned, so I had done nothing with Notepad or anything else yet. I’ve informed PyCharm of the issue, hopefully they’ll look into because I do like it.

Thanks for the heads up that this can occur in any IDE, depending on the various factors.