Source code string cannot contain null bytes ошибка

I’m using Max OS X 10.10.3, and I finally got the graphics.py to show in Python 3, before it was saying no module existed.

However, now when I try import graphics, or from graphics import *, I get the message:

"source code string cannot contain null bytes"

Does any Mac user (using Python 3) perhaps know what is wrong? Has anyone used the Zelle book and his graphics.py module? Thanks.

WhiZTiM's user avatar

WhiZTiM

21.1k4 gold badges42 silver badges68 bronze badges

asked Jul 5, 2015 at 18:46

Peter G. Williams's user avatar

5

For posterity: I had the same problem and fixed it using,

sed -i 's/x0//g' FILENAME

The file seemed to be messed up in numerous ways (wrong endings, etc); no idea how…

See https://stackoverflow.com/a/2399817/230468

Community's user avatar

answered Aug 22, 2016 at 19:39

DilithiumMatrix's user avatar

DilithiumMatrixDilithiumMatrix

17.5k22 gold badges76 silver badges118 bronze badges

1

I am using Visual Studio Code, the encoding was set to UTF-16 LE.
You can check the encoding on the right bottom side of VSCode. Just click on the encoding and select «save with encoding» and select UTF-8. It worked perfectly.

answered Jun 13, 2019 at 4:42

Paco Meraz's user avatar

1

I got this message when I wanted to use eval for my input for my function that sometimes it takes string or int/float but when it takes numpy numbers, it throws this exception, eval(number).

My solution was eval(str(number)).

answered Aug 5, 2019 at 6:09

Habib Karbasian's user avatar

I just encountered this problem, which is usually caused by the encoding format. You can use Notepad++ to change the encoding format of python files to UTF-8.

answered Nov 28, 2018 at 3:20

Chaplin Hwang's user avatar

This kind of error is not from your project source code. This kind of error emerges from your python interpreter. So the best solution is to set your python interpreter in your project env directory. or set the interpreters virtual env properly using your IDE’s interpreter configuration.

answered Apr 23, 2016 at 9:15

Open your file with an editor that can show you all invisible character.
You will see where is the invalid char, just delete and re-type it.

If you are on mac you can do it with Coda > Open your file > Show invisible characters.

answered Apr 16, 2019 at 9:20

Fabio Caccamo's user avatar

1

  • Go to python folder python36/Lib/site-packages/scipy/
  • Open __init__.py

Change:

from scipy._lib._testutils import PytestTester

to:

from scipy._lib.test__testutils import PytestTester

It worked on my windows 7

Jay Dorsey's user avatar

Jay Dorsey

3,5232 gold badges18 silver badges24 bronze badges

answered Jul 26, 2019 at 16:30

Atharva Panage's user avatar

1

I created a file using windows terminal echo «hello» > hello.py and got this issue. I resolved by creating a new file from notepad

answered May 30, 2021 at 6:42

Janarthanan Ramu's user avatar

My problem was the python interpreter, try changing it to the right python directory path

answered Nov 18, 2021 at 14:55

Harel Malichi's user avatar

1

Many people ask questions like this, BUT many of them are using not standart library, so their error can be explained (for me). I used standart Tkinter library but i get this error too.

  File "C:/Users/Panda/Desktop/Пайтон/enter_symbol.py", line 5, in <module>
    exec(f'tk.bind({chr(num)},lambda event:print("You entered:",{chr(num)}))')
ValueError: source code string cannot contain null bytes

My code:

from tkinter import Tk
tk=Tk()
tk.geometry('0x0+0+0')
for num in range(1000):
    exec(f"""
try:tk.bind({chr(num)},lambda event:print("You entered:",{chr(num)}))
except:None""")

What should I do to not get this error?

Do you experience getting the error message “source code string cannot contain null bytes“, whenever you attempt to import graphics, or from graphics import *? .This warning message is shown if the contents of the file include a byte that has a value that is a null value.

What is ValueErrror?

ValueError is the error in python that mostly occurs when you are passing the argument to the built-in functions of the right type. But the value of that argument is invalid. For example, suppose the function accepts an argument of integer type. And you are passing the value by converting the string to an integer. In this case, you will get the ValueErrror.

Solution for the source code string cannot contain null bytes

If you have been experiencing “source code string cannot contain null bytes” problem, then the following possible options may help you fix it:

Solution 1: Remove the null character

Remove the null character at the end of line 41 in the cTurtle.py because, for some unknown reason, line 41 of the cTurtle.py file includes a null character:

$ od -t a cTurtle.py.orig | grep -i nul

0003360 - - - - sp c T u r t l e . p y nul

After the removal of the null character, the module’s operations should go back to their normal state.

Solution 2: Use the sed command

If you want to remove the null characters that are in a file, you may do it quickly and simply by using the sed command that is indicated in the following example:

sed -i 's/x0//g' FILENAME

This method modifies the file in situ, which is critical if the file is still being used. Passing the parameter -i’ext’ generates a backup of the original file with the ‘ext’ suffix appended to it.

Solution 3: Use pipeline

In the event that the output of sed indicates that nothing was replaced, then you may make use of the following pipeable one-liner using Phyton:

python -c 'import sys; sys.stdout.write(sys.stdin.read().replace("", ""))'

You may also discover that some instructions do, in fact, leave the null bytes in place, despite the fact that they are no longer visible, at least not in a terminal running OS X. Hexdump is a useful tool for debugging situations like these.

Conclusion

ValueError is a python exception error that you will get when you are passing the argument to the function of an invalid type. The Valueerror: source code string cannot contain null bytes also comes due to this case. The above method will solve your problems regarding this error.

Traceback (most recent call last):
File «C:UsersINTELAppDataLocalProgramsPythonPython39Scriptspip-script.py», line 33, in
sys.exit(load_entry_point(‘pip==21.1.1’, ‘console_scripts’, ‘pip’)())
File «C:UsersINTELAppDataLocalProgramsPythonPython39Scriptspip-script.py», line 25, in importlib_load_entry_point
return next(matches).load()
File «c:usersintelappdatalocalprogramspythonpython39libimportlibmetadata.py», line 77, in load
module = import_module(match.group(‘module’))
File «c:usersintelappdatalocalprogramspythonpython39libimportlib_init_.py», line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File «», line 1030, in _gcd_import
File «», line 1007, in _find_and_load
File «», line 986, in _find_and_load_unlocked
File «», line 680, in _load_unlocked
File «», line 855, in exec_module
File «», line 228, in _call_with_frames_removed
File «c:usersintelappdatalocalprogramspythonpython39libsite-packagespip_internalclimain.py», line 9, in
from pip._internal.cli.autocompletion import autocomplete
File «c:usersintelappdatalocalprogramspythonpython39libsite-packagespip_internalcliautocompletion.py», line 10, in
from pip._internal.cli.main_parser import create_main_parser
File «c:usersintelappdatalocalprogramspythonpython39libsite-packagespip_internalclimain_parser.py», line 8, in
from pip._internal.cli import cmdoptions
File «c:usersintelappdatalocalprogramspythonpython39libsite-packagespip_internalclicmdoptions.py», line 23, in
from pip._internal.cli.parser import ConfigOptionParser
File «c:usersintelappdatalocalprogramspythonpython39libsite-packagespip_internalcliparser.py», line 12, in
from pip._internal.configuration import Configuration, ConfigurationError
File «c:usersintelappdatalocalprogramspythonpython39libsite-packagespip_internalconfiguration.py», line 27, in
from pip._internal.utils.misc import ensure_dir, enum
File «c:usersintelappdatalocalprogramspythonpython39libsite-packagespip_internalutilsmisc.py», line 38, in
from pip.vendor.tenacity import retry, stop_after_delay, wait_fixed
File «c:usersintelappdatalocalprogramspythonpython39libsite-packagespip_vendortenacity_init
.py», line 523, in
from pip.vendor.tenacity.tornadoweb import TornadoRetrying
File «c:usersintelappdatalocalprogramspythonpython39libsite-packagespip_vendortenacitytornadoweb.py», line 23, in
from tornado import gen
File «c:usersintelappdatalocalprogramspythonpython39libsite-packagestornadogen.py», line 81, in
from tornado.concurrent import (
File «c:usersintelappdatalocalprogramspythonpython39libsite-packagestornadoconcurrent.py», line 34, in
from tornado.log import app_log
File «c:usersintelappdatalocalprogramspythonpython39libsite-packagestornadolog.py», line 38, in
import colorama # type: ignore
File «c:usersintelappdatalocalprogramspythonpython39libsite-packagescolorama_init
.py», line 2, in
from .initialise import init,deinit,reinit,colorama_text
ValueError: source code string cannot contain null bytes

Since I am a Noob,I can’t understand the error here,can someone please explain what is wrong and how I can solve that

#python #django #intellij-idea

Вопрос:

Я новичок в Django и пытаюсь запустить свой сервер, но получаю это сообщение об ошибке. Есть ли помощь в том, как это исправить?

   File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "C:UsersFiercePCAppDataLocalProgramsPythonPython39libsite-packagesdjangocontribstaticfilesmanagementcommandsrunserver.py", line 3, in <module>
    from django.core.management.commands.runserver import (
  File "C:UsersFiercePCAppDataLocalProgramsPythonPython39libsite-packagesdjangocontribstaticfilesma
nagementcommandsrunserver.py", line 3, in <module>
    from django.core.management.commands.runserver import (
  File "C:UsersFiercePCAppDataLocalProgramsPythonPython39libsite-packagesdjangocoremanagementcomman
dsrunserver.py", line 10, in <module>
    from django.core.servers.basehttp import (
  File "C:UsersFiercePCAppDataLocalProgramsPythonPython39libsite-packagesdjangocoreserversbasehttp.
py", line 14, in <module>
    from wsgiref import simple_server
ValueError: source code string cannot contain null bytes
 

Я использую терминал IntelliJ для его запуска с python manage.py runserver

Попытался повторно сохранить и переписать его, чтобы убедиться, что он находится в UTF-8, и это так.

Комментарии:

1. Это типичный симптом поврежденного файла (системы). Проверьте свою файловую систему и переустановите ее.

Понравилась статья? Поделить с друзьями:
  • Source 11 brakes ошибка
  • Soundwire ошибка unable to connect soundwire server
  • Soundflower установщик обнаружил ошибку
  • Sound forge ошибка при открытии кодека
  • Soft 301 лада веста ошибка