6

I just installed Python and Django for the first time while following this tutorial on the Django site, and everything up to this part worked just fine and produced no errors.

Now I'm at the "The development server" section, and ran the command python manage.py runserver while in my project directory where the manage.py is located and I get this error:

Segmentation fault

Nothing else.

Anyone know what's going on here and how I can solve this?

If it matters, this is my manage.py file (the django in the from django.core.management ... line is marked as an error in my IDE (PyCharm) and the error says Unresolved reference 'django'):

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "davilex.settings")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)
3
  • if you think Unresolved reference is the issue .. you can find the relevant question in SO Commented Jan 12, 2016 at 4:37
  • 1
    A segmention fault usually related to a problem on a lower level than Python: C libraries, OS or even hardware. What system are you using? Commented Jan 12, 2016 at 4:47
  • Occurred for me when using Django with Postgres on python3.7. Created a venv based on python3.6 and it worked fine Commented Sep 10, 2018 at 14:34

5 Answers 5

4

This happened to me in a Django project where I had a lot of packages that had C-extensions. After I ran an Ubuntu system package update, I suddenly found that the manage.py command seg faulted. Turns out, some C-extensions link themselves to system libraries, and if a package update changes those libraries, it could cause the C-extensions to crash.

Since I had installed everything inside a Python virtualenv, I just deleted and regenerated it, and that fixed the error.

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

1 Comment

With pipenv, I needed to completely remove the directory of the virtualenv, just doing pipenv uninstall --all followed by pipenv install did not do the trick.
3

I had this same issue following the tutorial pretty much verbatim (except that I am using git-bash in Windows, and used "virtualenv" in place of "mkvirtualenv" and "source projectdir/Scripts/activate" in place of "workon projectdir".

Running

python -vvvvv manage.py runserver

Gave me the warning that I had migrations that needed running (which the tutorial says to ignore) with

python manage.py migrate

Which is presumably not a step you can really skip in some cases, despite what the tutorial says. After this, runserver worked without error.

Comments

2
  1. install PyMysql:

    python3 -m pip install PyMysql

  2. Setting add mysql conf:

    DATABASES = {  
        'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'your database name',
        'USER': 'your user',
        'PASSWORD': 'your pwd',
        'HOST': 'ip',
        'PORT': 'port',
        }
    }
    
  3. __init__.py add
    import pymysql
    pymysql.install_as_MySQLdb()

enjoy~

Comments

1

I had a similar issue while setting up a project on mac. In the end, turned out it because of value set in DATABASES.

DATABASES = {
    'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'blue9',
    'USER': 'root',
    'PASSWORD': 'root',
    'PORT': '',
    'HOST': ''
}

Empty value of the 'PORT' and 'HOST' was causing the problem. These keys should not have an empty value. Either provide a finite value or don't specify them at all.

Comments

1

I think this issue related database config, first step check postgres library install config

pip install psycopg2-binary==2.8.5

second step check database config in django project settings :

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': '<database_name>',
    'USER': '<user_name>',
    'PASSWORD': '<password>',
    'HOST': '<host-name>',
    'PORT': '<port number : default : 5432>',
}

}

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.