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)
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.
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.
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.
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>',
}
}
install PyMysql:
python3 -m pip install PyMysql
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', } }
__init__.py add import pymysql
pymysql.install_as_MySQLdb()
enjoy~
Just put in sudo before running migration or run server command. For example if you want to run migrate then use
sudo python manage.py migrate
or if you want to run server
sudo python manage.py runserver
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.