当我进入时:
python manage.py runserver
进入我的常用文件夹,我得到以下输出:
C:\Users\user\projects\steveone\steveone>python manage.py runserver Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\__init__.py", line 3, in <module>
from django.utils.version import get_version
File "C:\Users\user\Anaconda3\lib\site-packages\django\utils\version.py", line 5, in <module>
import subprocess
File "C:\Python34\Lib\subprocess.py", line 395, in <module>
import threading
File "C:\Python34\Lib\threading.py", line 10, in <module>
from traceback import format_exc as _format_exc
File "C:\Python34\Lib\traceback.py", line 3, in <module>
import linecache
File "C:\Python34\Lib\linecache.py", line 10, in <module>
import tokenize
File "C:\Python34\Lib\tokenize.py", line 32, in <module>
import re
File "C:\Python34\Lib\re.py", line 123, in <module>
import sre_compile
File "C:\Python34\Lib\sre_compile.py", line 18, in <module>
assert _sre.MAGIC == MAGIC, "SRE module mismatch"
AssertionError: SRE module mismatch
我没有运行virtualenv(我知道),这只是在我今天通过JBDC将LibreOffice连接到MySQL后才开始发生的。从我收集的内容来看,我感觉它可能与路径有关,但我并不确定。我对网络开发还很陌生,但到目前为止,我已经能够找到我遇到的问题的答案。我昨天开始运行,这种情况只发生在我摆弄数据库之后。
编辑1:我已经尝试过重新安装anaconda的建议,但错误仍然存在。我得到了和以前一样的错误。
答案 0 :(得分:1)
好的,经过几天和一些书呆子,我找到了解决方案。
我按顺序卸载了django,anaconda和python。
我按顺序重新安装了anaconda和django。
这使我的anaconda文件夹中的python.exe成为我的主要python应用程序。 (?)
然后我补充道:
C:\ Program Files \ MySQL \ MySQL Server 5.7 \ bin 进入我的系统环境变量路径。
在此之后我尝试用
运行应用程序python manage.py runserver
但我得到了错误:
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x00000147B66DEAE8>
Traceback (most recent call last):
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\db\backends\mysql\base.py", line 26, in <module>
import MySQLdb as Database
ModuleNotFoundError: No module named 'MySQLdb'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\core\management\commands\runserver.py", line 117, in inner_run
autoreload.raise_last_exception()
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 251, in raise_last_exception
six.reraise(*_exception)
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\utils\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models()
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\apps\config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\Kevin\Anaconda3\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\contrib\auth\models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\contrib\auth\base_user.py", line 52, in <module>
class AbstractBaseUser(models.Model):
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\db\models\base.py", line 124, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\db\models\base.py", line 325, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Users\Kevin\Anaconda3\lib\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 "C:\Users\Kevin\Anaconda3\lib\site-packages\django\db\__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\db\utils.py", line 211, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\db\utils.py", line 115, in load_backend
return import_module('%s.base' % backend_name)
File "C:\Users\Kevin\Anaconda3\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\Kevin\Anaconda3\lib\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: No module named 'MySQLdb'.
Did you install mysqlclient or MySQL-python?
C:\Users\Kevin\projects\steveone\steveone> Error loading MySQLdb module: No module named 'MySQLdb'.
'Error' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\Kevin\projects\steveone\steveone>python manage.py runserver
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x000002889B6AEAE8>
Traceback (most recent call last):
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\db\backends\mysql\base.py", line 26, in <module>
import MySQLdb as Database
ModuleNotFoundError: No module named 'MySQLdb'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\core\management\commands\runserver.py", line 117, in inner_run
autoreload.raise_last_exception()
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 251, in raise_last_exception
six.reraise(*_exception)
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\utils\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models()
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\apps\config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\Kevin\Anaconda3\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\contrib\auth\models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\contrib\auth\base_user.py", line 52, in <module>
class AbstractBaseUser(models.Model):
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\db\models\base.py", line 124, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\db\models\base.py", line 325, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Users\Kevin\Anaconda3\lib\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 "C:\Users\Kevin\Anaconda3\lib\site-packages\django\db\__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\db\utils.py", line 211, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\Users\Kevin\Anaconda3\lib\site-packages\django\db\utils.py", line 115, in load_backend
return import_module('%s.base' % backend_name)
File "C:\Users\Kevin\Anaconda3\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\Kevin\Anaconda3\lib\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: No module named 'MySQLdb'.
Did you install mysqlclient or MySQL-python?
我尝试使用
pip install MySQL-python
但那是给了我
Collecting MySQL-python
Using cached MySQL-python-1.2.5.zip
Building wheels for collected packages: MySQL-python
Running setup.py bdist_wheel for MySQL-python ... error
Complete output from command C:\Users\Kevin\Anaconda3\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Kevin\\AppData\\Local\\Temp\\pip-build-_yvqinya\\MySQL-python\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d C:\Users\Kevin\AppData\Local\Temp\tmpy1lf3g11pip-wheel- --python-tag cp36:
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-3.6
copying _mysql_exceptions.py -> build\lib.win-amd64-3.6
creating build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\__init__.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\converters.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\connections.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\cursors.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\release.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\times.py -> build\lib.win-amd64-3.6\MySQLdb
creating build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\__init__.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\CR.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\ER.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\FLAG.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\REFRESH.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\CLIENT.py -> build\lib.win-amd64-3.6\MySQLdb\constants
running build_ext
building '_mysql' extension
creating build\temp.win-amd64-3.6
creating build\temp.win-amd64-3.6\Release
cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include" -IC:\Users\Kevin\Anaconda3\include -IC:\Users\Kevin\Anaconda3\include /Tc_mysql.c /Fobuild\temp.win-amd64-3.6\Release\_mysql.obj /Zl
error: command 'cl.exe' failed: No such file or directory
----------------------------------------
Failed building wheel for MySQL-python
Running setup.py clean for MySQL-python
Failed to build MySQL-python
Installing collected packages: MySQL-python
Running setup.py install for MySQL-python ... error
Complete output from command C:\Users\Kevin\Anaconda3\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Kevin\\AppData\\Local\\Temp\\pip-build-_yvqinya\\MySQL-python\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\Kevin\AppData\Local\Temp\pip-w7u4ethq-record\install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_py
creating build
creating build\lib.win-amd64-3.6
copying _mysql_exceptions.py -> build\lib.win-amd64-3.6
creating build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\__init__.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\converters.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\connections.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\cursors.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\release.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\times.py -> build\lib.win-amd64-3.6\MySQLdb
creating build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\__init__.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\CR.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\ER.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\FLAG.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\REFRESH.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\CLIENT.py -> build\lib.win-amd64-3.6\MySQLdb\constants
running build_ext
building '_mysql' extension
creating build\temp.win-amd64-3.6
creating build\temp.win-amd64-3.6\Release
cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include" -IC:\Users\Kevin\Anaconda3\include -IC:\Users\Kevin\Anaconda3\include /Tc_mysql.c /Fobuild\temp.win-amd64-3.6\Release\_mysql.obj /Zl
error: command 'cl.exe' failed: No such file or directory
所以我首先尝试通过各种方法解决这个问题,但都失败了。 包括更新设置工具和滚轮:
pip install -U setuptools
pip install -U wheel
并运行msi安装程序:
MySQL的连接器的Python-2.1.7-py3.4 - 窗口x86-64位
失败(文档中描述的两种方式)。
所以我决定尝试通过Mysqlclient实现连接:
pip install mysqlclient
修复了问题,现在应用运行了。
最后,我只能推测问题是什么,如果有人读到这些并且回想起来有一些想法,那么我很乐意听到它们。