Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

psycopg2 is required for ArrayField even if project isn't using postgres #100

Open
AngelOnFira opened this issue Jul 9, 2021 · 3 comments
Assignees
Labels

Comments

@AngelOnFira
Copy link
Collaborator

Even though I'm not using Postgres for Django (just yet), the use of ArrayFields requires me to have it installed.

Traceback (most recent call last):
  File "/home/forest/Documents/git/megagame-controller/django/manage.py", line 22, in <module>
    main()
  File "/home/forest/Documents/git/megagame-controller/django/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/home/forest/.cache/pypoetry/virtualenvs/backend-6PFENasO-py3.9/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/home/forest/.cache/pypoetry/virtualenvs/backend-6PFENasO-py3.9/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/forest/.cache/pypoetry/virtualenvs/backend-6PFENasO-py3.9/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/forest/.cache/pypoetry/virtualenvs/backend-6PFENasO-py3.9/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/home/forest/Documents/git/megagame-controller/django/player/management/commands/seed.py", line 27, in handle
    seeder = Seed.seeder(locale="en_CA")
  File "/home/forest/.cache/pypoetry/virtualenvs/backend-6PFENasO-py3.9/lib/python3.9/site-packages/django_seed/__init__.py", line 43, in seeder
    from django_seed import seeder
  File "/home/forest/.cache/pypoetry/virtualenvs/backend-6PFENasO-py3.9/lib/python3.9/site-packages/django_seed/seeder.py", line 6, in <module>
    from django_seed.guessers import NameGuesser, FieldTypeGuesser
  File "/home/forest/.cache/pypoetry/virtualenvs/backend-6PFENasO-py3.9/lib/python3.9/site-packages/django_seed/guessers.py", line 5, in <module>
    from django.contrib.postgres.fields import ArrayField
  File "/home/forest/.cache/pypoetry/virtualenvs/backend-6PFENasO-py3.9/lib/python3.9/site-packages/django/contrib/postgres/fields/__init__.py", line 1, in <module>
    from .array import *  # NOQA
  File "/home/forest/.cache/pypoetry/virtualenvs/backend-6PFENasO-py3.9/lib/python3.9/site-packages/django/contrib/postgres/fields/array.py", line 3, in <module>
    from django.contrib.postgres import lookups
  File "/home/forest/.cache/pypoetry/virtualenvs/backend-6PFENasO-py3.9/lib/python3.9/site-packages/django/contrib/postgres/lookups.py", line 4, in <module>
    from .search import SearchVector, SearchVectorExact, SearchVectorField
  File "/home/forest/.cache/pypoetry/virtualenvs/backend-6PFENasO-py3.9/lib/python3.9/site-packages/django/contrib/postgres/search.py", line 1, in <module>
    import psycopg2
ModuleNotFoundError: No module named 'psycopg2'
@AngelOnFira AngelOnFira added the bug label Jul 9, 2021
@AngelOnFira AngelOnFira self-assigned this Jul 9, 2021
@N1K1TAS95
Copy link

pip install psycopg2-binary inside your venv

@Vftdan
Copy link

Vftdan commented Dec 2, 2021

Possible solution:

from django.contrib.postgres.fields import ArrayField

try:
    from django.contrib.postgres.fields import ArrayField
except ImportError:
    ArrayField = None

if isinstance(field, ArrayField):

        if ArrayField is not None and isinstance(field, ArrayField):

And the same thing for JSONField.

@EliasOPrado
Copy link

Installing psycopg2-binary�worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants