关于pip:ImportError:没有名为’ConfigParser’的模块

ImportError: No module named 'ConfigParser'

环境:视静脉Python3.6

在Venv启动Django,mysqlremind无链接

在Venv启动Django,mysqlremind无链接在Venv启动Django,mysqlremind no links在venv启动django,mysqlremind no links在venv启动django,mysqlremind no links在venv启动django,mysqlremind no links在venv启动django,mysqlremind无链接

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
python manage.py runserver
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x103a88048>
Traceback (most recent call last):
  File"/Users/VANXV/python/venvdjango186/lib/python3.5/site-packages/django/db/backends/mysql/base.py", line 24, in <module>
    import MySQLdb as Database
ImportError: No module named 'MySQLdb'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File"/Users/VANXV/python/venvdjango186/lib/python3.5/site-packages/django/utils/autoreload.py", line 229, in wrapper
    fn(*args, **kwargs)
  File"/Users/VANXV/python/venvdjango186/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 107, in inner_run
    autoreload.raise_last_exception()
  File"/Users/VANXV/python/venvdjango186/lib/python3.5/site-packages/django/utils/autoreload.py", line 252, in raise_last_exception
    six.reraise(*_exception)
  File"/Users/VANXV/python/venvdjango186/lib/python3.5/site-packages/django/utils/six.py", line 658, in reraise
    raise value.with_traceback(tb)
  File"/Users/VANXV/python/venvdjango186/lib/python3.5/site-packages/django/utils/autoreload.py", line 229, in wrapper
    fn(*args, **kwargs)
  File"/Users/VANXV/python/venvdjango186/lib/python3.5/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File"/Users/VANXV/python/venvdjango186/lib/python3.5/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File"/Users/VANXV/python/venvdjango186/lib/python3.5/site-packages/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File"/Users/VANXV/python/venvdjango186/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File"<frozen importlib._bootstrap>", line 986, in _gcd_import
  File"<frozen importlib._bootstrap>", line 969, in _find_and_load
  File"<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File"<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File"<frozen importlib._bootstrap_external>", line 665, in exec_module
  File"<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File"/Users/VANXV/python/venvdjango186/lib/python3.5/site-packages/django/contrib/auth/models.py", line 41, in <module>
    class Permission(models.Model):
  File"/Users/VANXV/python/venvdjango186/lib/python3.5/site-packages/django/db/models/base.py", line 139, in __new__
    new_class.add_to_class('_meta', Options(meta, **kwargs))
  File"/Users/VANXV/python/venvdjango186/lib/python3.5/site-packages/django/db/models/base.py", line 324, in add_to_class
    value.contribute_to_class(cls, name)
  File"/Users/VANXV/python/venvdjango186/lib/python3.5/site-packages/django/db/models/options.py", line 250, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File"/Users/VANXV/python/venvdjango186/lib/python3.5/site-packages/django/db/__init__.py", line 36, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File"/Users/VANXV/python/venvdjango186/lib/python3.5/site-packages/django/db/utils.py", line 241, in __getitem__
    backend = load_backend(db['ENGINE'])
  File"/Users/VANXV/python/venvdjango186/lib/python3.5/site-packages/django/db/utils.py", line 112, in load_backend
    return import_module('%s.base' % backend_name)
  File"/Users/VANXV/python/venvdjango186/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File"<frozen importlib._bootstrap>", line 986, in _gcd_import
  File"<frozen importlib._bootstrap>", line 969, in _find_and_load
  File"<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File"<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File"<frozen importlib._bootstrap_external>", line 665, in exec_module
  File"<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File"/Users/VANXV/python/venvdjango186/lib/python3.5/site-packages/django/db/backends/mysql/base.py", line 27, in <module>
    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 pip install MySQL-python
    Collecting MySQL-python
      Using cached MySQL-python-1.2.5.zip
        Complete output from command python setup.py egg_info:
        Traceback (most recent call last):
          File"<string>", line 1, in <module>
          File"/private/var/folders/b2/3clz71qj661cjh_b3wg2jqcm0000gn/T/pip-build-zqh44_1k/MySQL-python/setup.py", line 13, in <module>
            from setup_posix import get_config
          File"/private/var/folders/b2/3clz71qj661cjh_b3wg2jqcm0000gn/T/pip-build-zqh44_1k/MySQL-python/setup_posix.py", line 2, in <module>
            from ConfigParser import SafeConfigParser
        ImportError: No module named 'ConfigParser'

        ----------------------------------------
    Command"python setup.py egg_info" failed with error code 1 in /private/var/folders/b2/3clz71qj661cjh_b3wg2jqcm0000gn/T/pip-build-zqh44_1k/MySQL-python/


此问题列在Github官方回购协议上:

This change should do it. There were some minor incompatibilities with python 3 within django-mysqlndb-backend itself, but also the MySQL-python dependency is not python 3 compatible (which is where your ConfigParser error was coming from), whereas mysqlclient is. You may need to uninstall MySQL-python before reinstalling django-mysqlndb-backend in order for it to pull in the correct package.

Unfortunately someone created a PyPI package for this library on our behalf (it appears that it might be @enriqueaf ?) So unless they give the PyPi user"theatlantic" write access to that package you will just have to pip install from source. I recommend pinning it to a tag, e.g.:

1
pip install -e git+git://github.com/theatlantic/[email protected]#egg=django-mysqlndb-backend

这个问题也被问到了。