Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrade to Django 2.2: AttributeError: module 'statistics' has no attribute 'pstdev'

Current setup:

Python 3.6

Django==2.2
gunicorn==19.1.0
coverage==4.4.1
django-suit==0.2.26
django-extensions==2.0.6
djangorestframework==3.8.2
djangorestframework-datatables==0.3.0
djangorestframework-csv==2.1.0
coreapi==2.3.3
Faker==0.9.0
pillow==5.2.0
simple-crypt==4.1.7
xlrd==1.1.0
django-crequest==2018.5.11
gitpython==2.1.11
django_icons==0.2.1

Upgraded Django from 1.11 to 2.2. After cleaning up some obvious stuff as described in various upgrade checklists, got stuck on this one which does not seem to be answered anywhere. Migration chokes on some "statistics" module. Probably some dependent module is not compatible anymore with upgraded Django:

Trying:

> python manage.py runserver

Getting:

File "/Users/myuser/.local/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py", line 230, in get_new_connection
    conn.create_aggregate('STDDEV_POP', 1, list_aggregate(statistics.pstdev))
AttributeError: module 'statistics' has no attribute 'pstdev'

The full traceback:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/Users/myuser/miniconda3/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/Users/myuser/miniconda3/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/myuser/.local/lib/python3.5/site-packages/django/utils/autoreload.py", line 54, in wrapper
    fn(*args, **kwargs)
  File "/Users/myuser/.local/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 120, in inner_run
    self.check_migrations()
  File "/Users/myuser/.local/lib/python3.5/site-packages/django/core/management/base.py", line 453, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  File "/Users/myuser/.local/lib/python3.5/site-packages/django/db/migrations/executor.py", line 18, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/Users/myuser/.local/lib/python3.5/site-packages/django/db/migrations/loader.py", line 49, in __init__
    self.build_graph()
  File "/Users/myuser/.local/lib/python3.5/site-packages/django/db/migrations/loader.py", line 212, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/Users/myuser/.local/lib/python3.5/site-packages/django/db/migrations/recorder.py", line 73, in applied_migrations
    if self.has_table():
  File "/Users/myuser/.local/lib/python3.5/site-packages/django/db/migrations/recorder.py", line 56, in has_table
    return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
  File "/Users/myuser/.local/lib/python3.5/site-packages/django/db/backends/base/base.py", line 256, in cursor
    return self._cursor()
  File "/Users/myuser/.local/lib/python3.5/site-packages/django/db/backends/base/base.py", line 233, in _cursor
    self.ensure_connection()
  File "/Users/myuser/.local/lib/python3.5/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
    self.connect()
  File "/Users/myuser/.local/lib/python3.5/site-packages/django/db/backends/base/base.py", line 195, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/Users/myuser/.local/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py", line 230, in get_new_connection
    conn.create_aggregate('STDDEV_POP', 1, list_aggregate(statistics.pstdev))
AttributeError: module 'statistics' has no attribute 'pstdev'

Thank you for suggestions.

like image 208
SwissNavy Avatar asked Nov 16 '25 22:11

SwissNavy


1 Answers

You probably have a custom statistics module that overrides the one provided by the standard library. Rename the custom statistics module to fix the issue.

like image 181
Pramod Avatar answered Nov 18 '25 14:11

Pramod