Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
893 views
in Technique[技术] by (71.8m points)

python - Illegal instruction: 4 when running Django

I made clean install of Django v1.11.10 now. When I run python manage.py runserver everything works fine. But when I try connect to Postgres database, I install package pip install psycopg2, modify DATABASES varibale and after running runserver command it fails with Illegal instruction error:

Performing system checks...

System check identified no issues (0 silenced).
Illegal instruction: 4

What is it? How to get log error? I use Mac OS 10.11.6, PostgresApp (tried on v9 and v10 server to check error source). Python 3.6.4 (via virtualenv).

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

Error is the same if I set NAME or USER incorrect or even if I turn off Postgres.app server. It's like Django does not see Postgres. But with phpPgAdmin I can connect to Postgres server.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

psycopg2 is partly written in C and needs to be compiled. When you pip install a package, there's often a pre-compiled binary wheel available for download.

For some reason, the pre-compiled psycopg2 module contains instructions that your CPU can't recognize (probably because your processor is too old). You can fix this by compiling the module yourself, which will ensure the code works on your CPU:

$ pip install --no-binary psycopg2 psycopg2

--no-binary psycopg2 is a separate option so you'll have to specify the package name twice. You can include this in your requirements.txt as well:

psycopg2==a.b.c    --no-binary psycopg2

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...