简体   繁体   English

MySQL-python安装在virtualenv中不起作用

[英]MySQL-python installation not working within virtualenv

I am trying to connect a MySQL database to my Django project, but when I try to install MySQL-python, it gives me the following error: 我正在尝试将MySQL数据库连接到我的Django项目,但是当我尝试安装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/fr/3k1nrq490dzdz9s48k49m9640000gn/T/pip-build-4dsuxwwv/mysql-python/setup.py", line 13, in <module>
        from setup_posix import get_config
      File "/private/var/folders/fr/3k1nrq490dzdz9s48k49m9640000gn/T/pip-build-4dsuxwwv/mysql-python/setup_posix.py", line 2, in <module>
        from ConfigParser import SafeConfigParser
    ModuleNotFoundError: No module named 'ConfigParser'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/fr/3k1nrq490dzdz9s48k49m9640000gn/T/pip-build-4dsuxwwv/mysql-python/

I have tried pip3 install ConfigParser , but while it gets installed, the error still occurs. 我试过pip3 install ConfigParser ,但是在安装时,仍然会发生错误。

When I try to run my Django server, it prints out a long error log, and at the end: 当我尝试运行Django服务器时,它会打印出很长的错误日志,并在最后显示:

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?

and when I looked at the following link, it said that I should install MySQL-python: Django mysqlclient install 当我查看以下链接时,它说我应该安装MySQL-python: Django mysqlclient install

May seem like a newbie question, but I can't seem to find similar errors elsewhere online. 似乎是一个新手问题,但我似乎无法在其他在线位置找到类似的错误。

EDIT:: Ok, looks like MySQL-python is not for python-3.6 编辑::好的,看起来MySQL-python不适合python-3.6

While I did pip3 install mysqlclient , the virtualenv is saying that I have already installed it when I run the command again. 当我完成pip3 install mysqlclientpip3 install mysqlclient ,virtualenv表示再次运行命令时我已经安装了它。 But when I try to python3 manage.py runserver , I get the above error, asking if I had installed it. 但是当我尝试python3 manage.py runserver ,出现上述错误,询问是否已安装它。 When I try to give an answer, I am unable to. 当我尝试给出答案时,我无法。 Everytime I press ENTER, it just creates a new line and the prompt is still active. 每当我按ENTER键时,它只会创建一个新行,并且提示仍处于活动状态。

The above error is preceded by the following text: 上面的错误之前带有以下文本:

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x1059d9048>
Traceback (most recent call last):
  File "/Users/karthikpullela/Desktop/Django-projects/QB-test/QB/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 15, in <module>
    import MySQLdb as Database
  File "/Users/karthikpullela/Desktop/Django-projects/QB-test/QB/lib/python3.6/site-packages/MySQLdb/__init__.py", line 19, in <module>
    import _mysql
ImportError: dlopen(/Users/karthikpullela/Desktop/Django-projects/QB-test/QB/lib/python3.6/site-packages/_mysql.cpython-36m-darwin.so, 2): Library not loaded: libmysqlclient.18.dylib
  Referenced from: /Users/karthikpullela/Desktop/Django-projects/QB-test/QB/lib/python3.6/site-packages/_mysql.cpython-36m-darwin.so
  Reason: image not found

The above exception was the direct cause of the following exception:

Python 3 does not include ConfigParser only has configparser Python 3不包括ConfigParser只有configparser

>>> import ConfigParser
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'ConfigParser'
>>> import configparser

Try Python 2.7 which still works if we use import ConfigParser 试试Python 2.7,如果我们使用import ConfigParser仍然可以使用

Try to install with different package, it has support for python 3. 尝试使用其他软件包安装,它具有对python 3的支持。

pip install mysqlclient

If there is error while installing in virtualenv, do install this first. 如果在virtualenv中安装时出错,请首先安装。

sudo apt-get -y install python3-dev libmysqlclient-dev

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM