Forums

Collectstatic failed with pa_autoconfigure_django.py

I am using pythonanywhere for the first time. I want to deploy one django app. The required versions are django>=2.0 and python>=3.6. I am using the following commands:

pip3.6 install --user pythonanywhere

then,

pa_autoconfigure_django.py https://github.com/DEBADRIBASAK/MyFirstBlog.git --nuke

(I am using --nuke because there was a web-app previously and I wanted to remove it) It is collecting the required packages and it is failing at the collectstatic step:

< Running API sanity checks >
   \
    ~<:>>>>>>>>>
Cloning into '/home/ricky123/ricky123.pythonanywhere.com'...
remote: Enumerating objects: 48, done.
remote: Counting objects: 100% (48/48), done.
remote: Compressing objects: 100% (45/45), done.
remote: Total 48 (delta 6), reused 39 (delta 2), pack-reused 0
Unpacking objects: 100% (48/48), done.
Checking connectivity... done.

< Creating virtualenv with Python3.5 >
   \
    ~<:>>>>>>>>>
Removing ricky123.pythonanywhere.com...
Running virtualenv with interpreter /usr/bin/python3.5
Using base prefix '/usr'
New python executable in /home/ricky123/.virtualenvs/ricky123.pythonanywhere.com/bin/python3.5
Also creating executable in /home/ricky123/.virtualenvs/ricky123.pythonanywhere.com/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /home/ricky123/.virtualenvs/ricky123.pythonanywhere.com/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/ricky123/.virtualenvs/ricky123.pythonanywhere.com/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/ricky123/.virtualenvs/ricky123.pythonanywhere.com/bin/preactivate
virtualenvwrapper.user_scripts creating /home/ricky123/.virtualenvs/ricky123.pythonanywhere.com/bin/postactivate
virtualenvwrapper.user_scripts creating /home/ricky123/.virtualenvs/ricky123.pythonanywhere.com/bin/get_env_details

< Pip installing django (this may take a couple of minutes) >
   \
    ~<:>>>>>>>>>
Looking in links: /usr/share/pip-wheels
Collecting django
  Using cached https://files.pythonhosted.org/packages/fd/9a/0c028ea0fe4f5803dda1a7afabeed958d0c8b79b0fe762ffbf728db3b90d/Django-2.1.4-py3-none-any.whl
Collecting pytz (from django)
  Using cached https://files.pythonhosted.org/packages/f8/0e/2365ddc010afb3d79147f1dd544e5ee24bf4ece58ab99b16fbb465ce6dc0/pytz-2018.7-py2.py3-none-any.whl
Installing collected packages: pytz, django
Successfully installed django-2.1.4 pytz-2018.7

< Creating web app via API >
   \
    ~<:>>>>>>>>>

< Adding static files mappings for /static/ and /media/ >
   \
    ~<:>>>>>>>>>

< Updating wsgi file at /var/www/ricky123_pythonanywhere_com_wsgi.py >
   \
    ~<:>>>>>>>>>

< Updating settings.py >
   \
    ~<:>>>>>>>>>

< Running collectstatic >
   \
    ~<:>>>>>>>>>
Traceback (most recent call last):
  File "/home/ricky123/ricky123.pythonanywhere.com/manage.py", line 15, in <module>
    ~<:>>>>>>>>>
    execute_from_command_line(sys.argv)
  File "/home/ricky123/.virtualenvs/ricky123.pythonanywhere.com/lib/python3.5/site-packages/django/core/management/__init__.py", line 381, in execut
e_from_command_line
    utility.execute()
  File "/home/ricky123/.virtualenvs/ricky123.pythonanywhere.com/lib/python3.5/site-packages/django/core/management/__init__.py", line 375, in execut
e
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/ricky123/.virtualenvs/ricky123.pythonanywhere.com/lib/python3.5/site-packages/django/core/management/base.py", line 316, in run_from_a
rgv
    self.execute(*args, **cmd_options)
  File "/home/ricky123/.virtualenvs/ricky123.pythonanywhere.com/lib/python3.5/site-packages/django/core/management/base.py", line 353, in execute
    output = self.handle(*args, **options)
  File "/home/ricky123/.virtualenvs/ricky123.pythonanywhere.com/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectst
atic.py", line 188, in handle
    collected = self.collect()
  File "/home/ricky123/.virtualenvs/ricky123.pythonanywhere.com/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectst
atic.py", line 105, in collect
    for path, storage in finder.list(self.ignore_patterns):
  File "/home/ricky123/.virtualenvs/ricky123.pythonanywhere.com/lib/python3.5/site-packages/django/contrib/staticfiles/finders.py", line 125, in lis
t
    for path in utils.get_files(storage, ignore_patterns):
  File "/home/ricky123/.virtualenvs/ricky123.pythonanywhere.com/lib/python3.5/site-packages/django/contrib/staticfiles/utils.py", line 23, in get_fi
les
    directories, files = storage.listdir(location)
  File "/home/ricky123/.virtualenvs/ricky123.pythonanywhere.com/lib/python3.5/site-packages/django/core/files/storage.py", line 313, in listdir
    for entry in os.listdir(path):
FileNotFoundError: [Errno 2] No such file or directory: '/home/ricky123/static'
Traceback (most recent call last):
  File "/home/ricky123/.local/bin/pa_autoconfigure_django.py", line 52, in <module>
    main(arguments['<git-repo-url>'], arguments['--domain'], arguments['--python'], nuke=arguments.get('--nuke'))
  File "/home/ricky123/.local/bin/pa_autoconfigure_django.py", line 42, in main
    project.run_collectstatic()
  File "/home/ricky123/.local/lib/python3.6/site-packages/pythonanywhere/django_project.py", line 87, in run_collectstatic
    '--noinput',
  File "/usr/lib/python3.6/subprocess.py", line 291, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/home/ricky123/.virtualenvs/ricky123.pythonanywhere.com/bin/python', '/home/ricky123/ricky123.pythonanywhe
re.com/manage.py', 'collectstatic', '--noinput']' returned non-zero exit status 1.

Can anyone give any solution?

what happens if you just run a collect static on your django app yourself?

It is working properly when I use collectstatic on my cmd. But in this bash console of pythonanywhere it is not working.

I think Conrad meant, what happens if you try to run collectstatic in a bash console on PythonAnywhere:

  • Start up a bash console
  • Run workon ricky123.pythonanywhere.com to enter your virtualenv
  • cd /home/ricky123/ricky123.pythonanywhere.com to go to the directory containing your Django code
  • python manage.py collectstatic to run it.

Hopefully that will print out a more useful error message that we can use to debug the problem.

In pythonanywhere bash also it is working properly!

Cool

i am having the same idiotic issue.

have you tried the steps that giles outlined?

Same issue here.

Have you applied the solution provided by Giles above?

If you previously signed up for a PythonAnywhere account and had an error with collectstatic, you probably have an older version of SQLite (eg 3.8.2) for your account. In that case, sign up for a new account and try the commands in the PythonAnywhere section above.

yup- or you could also change your system image from your account settings. moving yourself to the newest system image will also do the same thing as setting up a new account.

I keep getting 'name' not defined too at the end of output.

(oidowu3.pythonanywhere.com) 23:36 ~/oidowu3.pythonanywhere.com (main)$ python manage.py 
createsuperuser
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/home/oidowu3/.virtualenvs/oidowu3.pythonanywhere.com/lib/python3.6/site-packages
/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/home/oidowu3/.virtualenvs/oidowu3.pythonanywhere.com/lib/python3.6/site-packages
/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/oidowu3/.virtualenvs/oidowu3.pythonanywhere.com/lib/python3.6/site-packages
/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/oidowu3/.virtualenvs/oidowu3.pythonanywhere.com/lib/python3.6/site-packages
/django/contrib/auth/management/commands/createsuperuser.py", line 79, in execute
    return super().execute(*args, **options)
  File "/home/oidowu3/.virtualenvs/oidowu3.pythonanywhere.com/lib/python3.6/site-packages
/django/core/management/base.py", line 393, in execute
    self.check()
  File "/home/oidowu3/.virtualenvs/oidowu3.pythonanywhere.com/lib/python3.6/site-packages
/django/core/management/base.py", line 423, in check
    databases=databases,
  File "/home/oidowu3/.virtualenvs/oidowu3.pythonanywhere.com/lib/python3.6/site-packages
/django/core/checks/registry.py", line 76, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "/home/oidowu3/.virtualenvs/oidowu3.pythonanywhere.com/lib/python3.6/site-packages
/django/core/checks/urls.py", line 13, in check_url_config
    return check_resolver(resolver)
  File "/home/oidowu3/.virtualenvs/oidowu3.pythonanywhere.com/lib/python3.6/site-packages
/django/core/checks/urls.py", line 23, in check_resolver
    return check_method()
  File "/home/oidowu3/.virtualenvs/oidowu3.pythonanywhere.com/lib/python3.6/site-packages
/django/urls/resolvers.py", line 416, in check
    for pattern in self.url_patterns:
  File "/home/oidowu3/.virtualenvs/oidowu3.pythonanywhere.com/lib/python3.6/site-packages
/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/oidowu3/.virtualenvs/oidowu3.pythonanywhere.com/lib/python3.6/site-packages
/django/urls/resolvers.py", line 602, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    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 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/oidowu3/oidowu3.pythonanywhere.com/mysite/urls.py", line 21, in <module>
    path('', include('blog.urls')),
NameError: name 'include' is not defined

Which Django version are you using?