如何在Windows 10上安装和使用适用于Python 3的MySQLdb? [英] How do I install and use MySQLdb for Python 3 on Windows 10?

查看:358
本文介绍了如何在Windows 10上安装和使用适用于Python 3的MySQLdb?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的各种搜索似乎都来自很老的帖子,或者提到了在cygwin下如何执行此操作.我安装了python 3.5,然后安装了Anaconda3.我的用户目录中安装了python 3.5(Cpython).我尝试更改事物在Windows环境变量路径中的显示顺序,以便可以同时使用Anaconda版本的Python和其他版本的Python.

My various searches seem to come up with very old posts or a mention of how to do this under cygwin. I had python 3.5 installed and then installed Anaconda3. I have python 3.5 (Cpython) installed in my user directory. I tried changing the order of how things appear in my Windows Environment Variables path, so that I could try both the Anaconda version of Python and the other version of python that I have.

当前,对于应该使用的程序包名称,我有些困惑.是python-mysqldb,还是MySQLdb,还是mysqldb,mysqlclient.我相信,当我在全局路径中使用Anaconda3(以及在用户路径中使用python的其他版本)时,我能够安装mysqlclient.

Currently, I am a bit confused as to the package name that I should use. Is it python-mysqldb, or MySQLdb, or mysqldb, mysqlclient. I believe that when I had Anaconda3 in my global path (and the other version of python in my user path), I was able to install mysqlclient.

最初,我只是尝试遵循培训站点上的教程,该站点涵盖数据库并使用peewee.

Initially, I am just trying to follow a tutorial from a training site that covers databases and uses peewee.

那么,可以为python3安装peewee的mysql驱动程序吗?还是专门在Windows上?

So, can the mysql driver for peewee be installed for python3? Or on Windows specifically?

使用sqlite3很容易,在生产中不用它,是吗?

It is easy enough to use sqlite3, one doesn't use that in production, is that right?

有人可以帮助我吗?提供一些指导吗?
同样,一种混乱的根源是,当google结果中列出了其他形式的python软件包安装时(很多指向堆栈溢出),例如使用easy_install或从git克隆某些内容.当我看到来自2010年的说明并且它们引用了easy_install时,我一直在想,现在我们可以只使用pip代替?另外,有时我看到使用了conda命令.这和点子一样吗?

Can someone help me? Provide some guidance?
Also, one source of confusion is when other forms of installation of a python package are listed in the google results (many point to stack overflow), such as using easy_install, or cloning something from git. When I see instructions that are from 2010 and they reference easy_install, I had been thinking that now we can just use pip instead? Also, sometimes I see use of the conda command. Does that work the same as pip?

预先感谢, 布鲁斯

推荐答案

您可以使用pymysql. "PyMySQL的目标是替代MySQLdb".在此处中查看文档.安装以下库

You could use pymysql. "The goal of PyMySQL is to be a drop-in replacement for MySQLdb". Check the docs here. Install the following libraries

pip安装mysqlclient pymysql

pip install mysqlclient pymysql

一旦安装了这些库,只需在项目的manage.py文件中添加这些行,然后使用mysql的数据库设置即可.

Once these libraries are installed, just add the lines in the manage.py file in your project and use the database settings for mysql.

导入pymysql

import pymysql

pymysql.install_as_MySQLdb()

pymysql.install_as_MySQLdb()

现在所有可以使用import MySQLdb的文件.

Now any files that import MySQLdb will work.

这篇关于如何在Windows 10上安装和使用适用于Python 3的MySQLdb?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆