Cannot start Seahub after upgrade to Ubuntu Server 20.04: ImportError: cannot import name 'CaptchaField' from 'captcha.fields'

Here is my seahub.log:

2020-11-04 00:53:49,611 [ERROR] django.request:132 handle_uncaught_exception Internal Server Error: /
Traceback (most recent call last):
  File "/opt/seafile/seafile-server-7.1.2/seahub/thirdpart/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/opt/seafile/seafile-server-7.1.2/seahub/thirdpart/django/core/handlers/base.py", line 244, in _legacy_get_response
    response = middleware_method(request)
  File "/opt/seafile/seafile-server-7.1.2/seahub/thirdpart/django/middleware/locale.py", line 24, in process_request
    i18n_patterns_used, prefixed_default_language = is_language_prefix_patterns_used(urlconf)
  File "/opt/seafile/seafile-server-7.1.2/seahub/thirdpart/django/conf/urls/i18n.py", line 29, in is_language_prefix_patterns_used
    for url_pattern in get_resolver(urlconf).url_patterns:
  File "/opt/seafile/seafile-server-7.1.2/seahub/thirdpart/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/opt/seafile/seafile-server-7.1.2/seahub/thirdpart/django/urls/resolvers.py", line 407, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/opt/seafile/seafile-server-7.1.2/seahub/thirdpart/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/opt/seafile/seafile-server-7.1.2/seahub/thirdpart/django/urls/resolvers.py", line 400, in     urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/opt/seafile/seafile-server-7.1.2/seahub/seahub/utils/rooturl.py", line 41, in <module>
    url(r'^%s' % settings.SITE_ROOT[1:], include(settings.SITE_ROOT_URLCONF)),
  File "/opt/seafile/seafile-server-7.1.2/seahub/thirdpart/django/conf/urls/__init__.py", line 50, in include
    urlconf_module = import_module(urlconf_module)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/opt/seafile/seafile-server-7.1.2/seahub/seahub/urls.py", line 8, in <module>
    from seahub.views.sysadmin import *
  File "/opt/seafile/seafile-server-7.1.2/seahub/seahub/views/sysadmin.py", line 96, in <module>
    from seahub.utils.two_factor_auth import has_two_factor_auth
  File "/opt/seafile/seafile-server-7.1.2/seahub/seahub/utils/two_factor_auth.py", line 5, in <module>
    from seahub.two_factor.views.login import (
  File "/opt/seafile/seafile-server-7.1.2/seahub/seahub/two_factor/views/__init__.py", line 2, in <module>
    from .core import SetupView, BackupTokensView, SetupCompleteView, QRGeneratorView
  File "/opt/seafile/seafile-server-7.1.2/seahub/seahub/two_factor/views/core.py", line 31, in <module>
    from seahub.auth.forms import AuthenticationForm
  File "/opt/seafile/seafile-server-7.1.2/seahub/seahub/auth/forms.py", line 17, in <module>
    from captcha.fields import CaptchaField
ImportError: cannot import name 'CaptchaField' from 'captcha.fields' (/usr/local/lib/python3.8/dist-packages/captcha/fields.py)

Here’s my pip3 list:

Package                Version
---------------------- --------------------
aggdraw                1.3.12
asgiref                3.3.0
attrs                  20.2.0
captcha                0.3
certifi                2020.6.20
chardet                3.0.4
command-not-found      0.3
cycler                 0.10.0
dbus-python            1.2.16
decorator              4.4.2
distro-info            0.23ubuntu1
Django                 3.1.3
django-appconf         1.0.4
django-formtools       2.2
django-post-office     3.3.0
django-pylibmc         0.6.1
django-ranged-response 0.2.0
django-recaptcha       2.0.6
django-simple-captcha  0.5.13
django-statici18n      2.0.1
docopt                 0.6.2
et-xmlfile             1.0.1
future                 0.18.2
gunicorn               20.0.4
idna                   2.8
imageio                2.9.0
jdcal                  1.4.1
Jinja2                 2.11.2
jsonfield2             3.0.3
kiwisolver             1.3.1
language-selector      0.1
MarkupSafe             1.1.1
matplotlib             3.3.2
mysqlclient            1.4.4
netifaces              0.10.4
networkx               2.5
numpy                  1.19.4
oauthlib               3.1.0
olefile                0.46
openpyxl               3.0.5
Pillow                 8.0.1
pip                    20.0.2
psd-tools              1.9.16
pyasn1                 0.4.2
pyasn1-modules         0.2.1
pycryptodome           3.9.9
PyGObject              3.36.0
PyJWT                  1.7.1
pylibmc                1.6.1
pyparsing              2.4.7
python-apt             2.0.0+ubuntu0.20.4.1
python-dateutil        2.8.1
python-ldap            3.2.0
python3-ldap           0.9.8.4
pytz                   2020.4
PyWavelets             1.1.1
PyYAML                 5.3.1
qrcode                 6.1
requests               2.22.0
requests-oauthlib      1.3.0
scikit-image           0.16.2
scipy                  1.5.3
setuptools             45.2.0
six                    1.14.0
SQLAlchemy             1.3.12
sqlparse               0.4.1
ubuntu-advantage-tools 20.3
ufw                    0.36
urllib3                1.25.8
wheel                  0.34.2

Short answer: I re-installed the pip3 module using
pip3 install --ignore-installed django-simple-captcha
and then restarted the seafile and seahub services - my problem was resolved.

Longer answer:
I was having the same problem, except I’ve upgraded from 7.0.5 to the 7.1.5 on Centos 7. With apologies, the steps I’ve taken should work on Ubuntu but I have not specifically tested these on that platform.

Background: (you can skip ahead to “My Solution” if you don’t care to read this part)
I received a related, but different message from above originally. Later I received the same error you were getting after I revisited the installation prerequisites at (link not allowed - see the seafile documentation) and made sure I had the prerequisites installed but that still didn’t resolve my issue.

As a test I launched python3 and from there typed (taken from the django documentation)
from django import forms
from captcha.fields import CaptchaField

and could see the error that was occurring.

“My Solution”: This worked for me - I hope it works for others too. Please remember to make a backup copy of your system in case this causes other issues for you!
I then executed this command:
pip3 install --ignore-installed django-simple-captcha
note: I repeated the python command line test from above and had a completely different error. I presumed there are pieces in the seafile programming that cover the pieces I’m neglecting in my simple test.
So next I restarted the seafile and seahub services - done , mine was back on track and functional.

I hope this solution works for you too!

3 Likes

What an annoying problem, my experience with pip is pretty limited but it seems to be fragile.

pip3 install --ignore-installed django-simple-captcha worked perfectly, thank you.

1 Like

I’m glad that worked for you too! Have a great one!

Worked as well for me! Upgrade to 20.10 worked as well fine.

Just worked for me running Seafile CE 8.0.5 on Ubuntu 20.04, clean install, that was throwing the CaptchaField Error. Thanks for posting!

For some background on --ignore-installed see here.