AUTOMATIC1111 / stable-diffusion-webui

Stable Diffusion web UI
GNU Affero General Public License v3.0
138.55k stars 26.31k forks source link

[Bug]: on a Mac when loading extensions the sidecar ._mycode.py file will be loaded causing a ValueError: source code string cannot contain null bytes error #11649

Open neal3000 opened 1 year ago

neal3000 commented 1 year ago

Is there an existing issue for this?

What happened?

The extension I was developing kept failing to load with ValueError: source code string cannot contain null bytes after much testing I determined the problem was a hidden side car file

user@xxx scripts % ls -ltra total 1024 drwxrwxrwx 1 xxx staff 131072 Jun 29 21:30 . drwxrwxrwx 1 xxx staff 131072 Jul 6 14:41 .. -rwxrwxrwx 1 xxx staff 4096 Jul 6 14:42 ._alpha.py -rwxrwxrwx@ 1 xxx staff 10 Jul 6 14:45 alpha.py

short term fix, delete files before running webui.sh long term fix, can you exclude loading .* hidden files in the module load code

Steps to reproduce the problem

  1. Go to .... extensions/xxx/scripts. , create alpha.py on a Mac using an editor that creates sidecar files (brackets,xcode..)
  2. run webui.sh
  3. ...

What should have happened?

it would be nice if .xxxxxx.py was ignored and not loaded as python code

Version or Commit where the problem happens

394ffa7b0a7fff3ec484bcd084e673a8b301ccc8

What Python version are you running on ?

Python 3.9.x (below, no recommended)

What platforms do you use to access the UI ?

MacOS

What device are you running WebUI on?

CPU

Cross attention optimization

Automatic

What browsers do you use to access the UI ?

Apple Safari

Command Line Arguments

none

List of extensions

building my own

Console logs

################################################################
Launching launch.py...
################################################################
Python 3.9.6 (default, May  7 2023, 23:32:44) 
[Clang 14.0.3 (clang-1403.0.22.14.1)]
Version: v1.4.0
Commit hash: 394ffa7b0a7fff3ec484bcd084e673a8b301ccc8
Installing requirements
Neal2 install.py

Launching Web UI with arguments: --update-all-extensions --skip-torch-cuda-test --upcast-sampling --no-half-vae --use-cpu interrogate
No module 'xformers'. Proceeding without it.
Warning: caught exception 'Torch not compiled with CUDA enabled', memory monitor disabled
*** Error loading script: ._gadzoinks.py
    Traceback (most recent call last):
      File "/Volumes/ExtremePro/stable-diffusion-webui/modules/scripts.py", line 274, in load_scripts
        script_module = script_loading.load_module(scriptfile.path)
      File "/Volumes/ExtremePro/stable-diffusion-webui/modules/script_loading.py", line 10, in load_module
        module_spec.loader.exec_module(module)
      File "<frozen importlib._bootstrap_external>", line 846, in exec_module
      File "<frozen importlib._bootstrap_external>", line 983, in get_code
      File "<frozen importlib._bootstrap_external>", line 913, in source_to_code
      File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
    ValueError: source code string cannot contain null bytes

Additional information

No response

missionfloyd commented 1 year ago

You could add dot_clean . to your webui-user.sh.