3

Guys I stuck this problem for couple weeks already. I have tried almost every answer I could find in stack overflow.

The error is below:

(venv1) Caimings-MacBook-Pro:yang NLStom$ python manage.py migrate
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/core/management/__init__.py", line 341, in execute
    django.setup()
  File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/apps/config.py", line 199, in import_models
    self.models_module = import_module(models_module_name)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/contrib/auth/models.py", line 4, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
    class AbstractBaseUser(models.Model):
  File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/db/models/base.py", line 119, in __new__
    new_class.add_to_class('_meta', Options(meta, app_label))
  File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/db/models/base.py", line 316, in add_to_class
    value.contribute_to_class(cls, name)
  File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/db/models/options.py", line 214, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/db/__init__.py", line 33, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/db/utils.py", line 211, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/db/utils.py", line 115, in load_backend
    return import_module('%s.base' % backend_name)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/db/backends/postgresql/base.py", line 24, in <module>
    raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: dlopen(/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Symbol not found: _PQbackendPID
  Referenced from: /Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/psycopg2/_psycopg.so
  Expected in: dynamic lookup

I tried to using PostgreSql for my database in Django. Below is code in my setting

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'play',
        'USER': 'uaa',
        'PASSWORD': '',
        'HOST': 'localhost',
        'PORT': '',
    }
}

What have I did in PostgreSql.

psql (9.5.4)
Type "help" for help.

NLStom=# CREATE uaa;
ERROR:  syntax error at or near "uaa"
LINE 1: CREATE uaa;
               ^
NLStom=# CREATE USER uaa;
CREATE ROLE
NLStom=# CREATE DATABASE play OWNER uaa;
CREATE DATABASE
NLStom=# \q

I used pip brew to install PostgreSql and used pip to install psycopg2. I have done all of these above in virtualenv.

Also wanna mention that I install Postgres.app in my mac.

5
  • try to use port 5432. Commented Oct 10, 2016 at 9:24
  • Thanks for the response! I change the port to 5432 in setting file. Same error.... T.T Commented Oct 10, 2016 at 9:31
  • 1
    Have you tried this one: stackoverflow.com/questions/1383126/… . It seems that both of you had the same problem. Commented Oct 10, 2016 at 9:36
  • Hey! I solved the problem. The problem is I have a 32 bit python in my virtualenv. I fix it by create a new virtualenv... Commented Oct 25, 2016 at 23:33
  • Thank your for your link though, bro! Commented Oct 25, 2016 at 23:46

2 Answers 2

1

Got similar issue on macOS 11.01, M1 Chip. Solved it by deleting the venv created by pycharm and recreating it manually with python3 -m venv /path/to/venv and then pip3 install -r requirements.txt. Following github issue could be helpful.

Sign up to request clarification or add additional context in comments.

Comments

0

I got a similar error, but once I verified that psql was in my PATH and the postgres server was running in the background, I reinstalled psycopg2 with conda install psycopg2, and my django postgres app worked fine.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.