File “<frozen importlib._bootstrap>“, line 219, in _call_with_frames_removed ValueError: source cod

问题:

学习github上大佬的python教程(42天)时遇到的问题

django中,为了创建models.py

python manage.py inspectdb > polls/models.py
python manage.py shell

执行这句后就出现了

Traceback (most recent call last):
  File "manage.py", line 20, in <module>
    main()
  File "manage.py", line 16, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\gg\Desktop\Dive Into Python\.venv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "C:\Users\gg\Desktop\Dive Into Python\.venv\lib\site-packages\django\core\management\__init__.py", line 377, in execute
    django.setup()
  File "C:\Users\gg\Desktop\Dive Into Python\.venv\lib\site-packages\django\__init__.py", line 24, in setup     
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\gg\Desktop\Dive Into Python\.venv\lib\site-packages\django\apps\registry.py", line 114, in populate
    app_config.import_models()
  File "C:\Users\gg\Desktop\Dive Into Python\.venv\lib\site-packages\django\apps\config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 674, in exec_module
  File "<frozen importlib._bootstrap_external>", line 781, in get_code
  File "<frozen importlib._bootstrap_external>", line 741, in source_to_code
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ValueError: source code string cannot contain null bytes

ValueError: source code string cannot contain null bytes


排查结果:

python manage.py inspectdb > polls/models.py
生成出来的文件models.py的文件格式不是utf8导致


解决方法

使用 notepad++ 等编辑器打开 models.py 改成 utf8格式就行了


答案发现处:

StackOverflow

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

路途遥远gg

帮到你了就好

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值