Django `collecstatic` returns `[Errno 13] Permission denied: '/code/static/admin/js/vendor/select2/i18n/pl.6031b4f16452.js.gz'`

I run my django app in Docker. I recently tried running collecstatic and instead was given this error code. Not sure what it means or what to do:

>docker-compose exec web python manage.py collectstatic
Traceback (most recent call last):
  File "/code/manage.py", line 22, in <module>
    main()
  File "/code/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 412, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 458, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 209, in handle
    collected = self.collect()
                ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 148, in collect
    for original_path, processed_path, processed in processor:
  File "/usr/local/lib/python3.11/site-packages/whitenoise/storage.py", line 162, in post_process_with_compression
    for name, compressed_name in self.compress_files(files_to_compress):
  File "/usr/local/lib/python3.11/site-packages/whitenoise/storage.py", line 199, in compress_files
    for compressed_path in compressor.compress(path):
  File "/usr/local/lib/python3.11/site-packages/whitenoise/compress.py", line 84, in compress
    yield self.write_data(path, compressed, ".gz", stat_result)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/whitenoise/compress.py", line 120, in write_data
    with open(filename, "wb") as f:
         ^^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: '/code/static/admin/js/vendor/select2/i18n/pl.6031b4f16452.js.gz'

I read somewhere that it may have to do with root privileges but I'm not sure which root privileges or how to go about remedying it.

I had the same issue.

Try:

chmod -R 755 /code/static

If it did not, work try running it as a different user.

Also you can temporarily disable compression in Whitenoise by setting WHITENOISE_USE_FINDERS to False in your settings:

`WHITENOISE_USE_FINDERS = False`
Back to Top