我正在用mysql设置django rest项目。我安装了所有依赖项,包括mysql-python:
-r, --rebase[=false|true|merges|preserve|interactive]
When true, rebase the current branch on top of the upstream branch after
fetching. If there is a remote-tracking branch corresponding to the upstream branch
and the upstream branch was rebased since last fetched, the rebase uses that
information to avoid rebasing non-local changes.
我需要进行一些调整,如此处Mac pip install mysql-python unsuccessful
所述现在,当我尝试运行Django==1.11.12
djangorestframework==3.8.2
django-cors-headers==2.2.0
drfdocs==0.0.11
mysql-python==1.2.5
django-rest-auth==0.9.3
django-allauth==0.35.0
nltk==3.2.5
django-extensions==2.0.7
pyparsing==2.2.0
pydot==1.2.4
时,出现以下错误:
python manage.py migrate
为什么会这样?我在Mac上,并且也安装了MySQL。
更新:
(VB_env) shannon:VB_Backend_SCG nitishpatkar$ python manage.py migrate
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute
django.setup()
File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models()
File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/apps/config.py", line 202, 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/nitishpatkar/Development/Vision Backlog rewrite/VB_env/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/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
class AbstractBaseUser(models.Model):
File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/db/models/base.py", line 124, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/db/models/base.py", line 325, in add_to_class
value.contribute_to_class(cls, name)
File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/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/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/db/__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/db/utils.py", line 211, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/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/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 30, in <module>
'Did you install mysqlclient or MySQL-python?' % e
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/_mysql.so, 2): Symbol not found: _mysql_affected_rows
Referenced from: /Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/_mysql.so
Expected in: flat namespace
in /Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/_mysql.so.
Did you install mysqlclient or MySQL-python?
更新2:
(VB_env) shannon:VB_Backend_SCG nitishpatkar$ pip install mysqlclient
Requirement already satisfied: mysqlclient in /Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages (1.3.12)
(VB_env) shannon:VB_Backend_SCG nitishpatkar$ python manage.py migrate
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute
django.setup()
File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models()
File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/apps/config.py", line 202, 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/nitishpatkar/Development/Vision Backlog rewrite/VB_env/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/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
class AbstractBaseUser(models.Model):
File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/db/models/base.py", line 124, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/db/models/base.py", line 325, in add_to_class
value.contribute_to_class(cls, name)
File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/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/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/db/__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/db/utils.py", line 211, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/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/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 30, in <module>
'Did you install mysqlclient or MySQL-python?' % e
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/_mysql.so, 2): Symbol not found: _mysql_affected_rows
Referenced from: /Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/_mysql.so
Expected in: flat namespace
in /Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/_mysql.so.
Did you install mysqlclient or MySQL-python?
(VB_env) shannon:VB_Backend_SCG nitishpatkar$
答案 0 :(得分:0)
您必须安装mysqlclient才能将mysql与django一起使用。
运行此命令
pip install mysqlclient
答案 1 :(得分:0)
在安装之前,请先进行“升级”和“更新”,然后再尝试安装“ mysqlclient”
答案 2 :(得分:0)
您可以尝试安装以下两个软件包并尝试
Python3
-> sudo apt-get install python-dev python3-dev
-> sudo apt-get install libmysqlclient-dev
Python2.7
-> sudo apt-get install python-dev python2.7-dev
-> sudo apt-get install libmysqlclient-dev