适用于python 3.7的MySQL软件包 [英] MySQL package for python 3.7

查看:533
本文介绍了适用于python 3.7的MySQL软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将数据保存到MySQL数据库中,我的问题是我找不到软件包...

I am in the need of saving data into a MySQL database, my problem is I can't find the package...

探索的解决方案:

试图从Pycharm安装MySQLdb表示不存在.

Trying to install MySQLdb from Pycharm it said non existing.

因此,如果有人可以替代python 3.7,或者知道如何获取3.7版的连接器,我会很高兴的.

So if anyone has an alternative to it for python 3.7, or knows how to get the connector for version 3.7 I would be happy.

推荐答案

有两种安装MySQL连接器的方法.第二种方法是首选.

There are two ways to install MySQL connector. The second way is preferred.

这是Oracle的产品安装程序.问题是它已经过时了.它只知道Python 3.6版,没有更新.要安装新版本的Python,请使用选项2.

This is Oracle's product installer. The problem is that it is outdated. It is only aware of Python version 3.6, and nothing newer. To install for a newer version of Python, use option 2.

Python软件包管理器随附于Python,名为 pip .它将从 PyPI 存储库下载该软件包,然后根据哪个Python版本(或哪个虚拟副本).您想要的软件包是mysql-connector-python.实际上,官方文档说,这是推荐的MySQL Connector的安装方法.

The Python package manager comes with Python, called pip. It downloads the package from the PyPI repository and installs it in an automatic location based on what version of Python (or what virtual copy) you use to install it. The package that you want is mysql-connector-python. In fact, the official documentation says this is the recommended method for installing the MySQL Connector.

例如,在Windows上,通过在开始"菜单中搜索打开命令提示符(cmd.exe).导航到安装pip的目录.或确保pip的目录包含在$ PATH变量中(您可以通过在开始"菜单中搜索"PATH"进行编辑).

For example, on Windows, open up the Command Prompt (cmd.exe) by searching in the Start Menu. Navigate to the directory where pip is installed. Or make sure that pip's directory is included in the $PATH variable (which you can edit by searching for "PATH" in the Start Menu).

命令提示符将显示以下内容:

The command prompt will show you this:

PS C:\Users\Ryan> 

除了显示我的用户名外,它会显示您的用户名或找到pip后导航到的路径,例如"C:\ blah \ blah".然后使用此命令...

except instead of my username, it'll show your username, or the path you navigated to after you found pip, like "C:\blah\blah". Then use this command...

输入:

pip install mysql-connector-python

它会下载并安装.

结果:

PS C:\Users\Ryan> pip install mysql-connector-python
Collecting mysql-connector-python
Downloading https://files.pythonhosted.org/packages/2d/65/3fc902c0f7635912800c6b935313b99b9d4426419ef7ba04f76231b24923/mysql_connector_python-8.0.12-py2.py3-none-any.whl (300kB)
    100% |████████████████████████████████| 307kB 1.1MB/s
Collecting protobuf>=3.0.0 (from mysql-connector-python)
Downloading https://files.pythonhosted.org/packages/77/78/a7f1ce761e2c738e209857175cd4f90a8562d1bde32868a8cd5290d58926/protobuf-3.6.1-py2.py3-none-any.whl (390kB)
    100% |████████████████████████████████| 399kB 1.8MB/s
Requirement already satisfied: setuptools in c:\users\ryan\appdata\local\programs\python\python37\lib\site-packages (from protobuf>=3.0.0->mysql-connector-python) (40.4.3)
Collecting six>=1.9 (from protobuf>=3.0.0->mysql-connector-python)
Using cached https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
Installing collected packages: six, protobuf, mysql-connector-python
Successfully installed mysql-connector-python-8.0.12 protobuf-3.6.1 six-1.11.0

此后,您可以通过显示您已经安装的所有软件包(不包括Python随附的标准库)来确保已安装:

Afterward, you can make sure it is installed by displaying all packages that have been installed by you (not including standard libraries, which come with Python):

输入:

PS C:\Users\Ryan> pip list

结果:

Package                Version
---------------------- -------
mysql-connector-python 8.0.12
pip                    18.0
protobuf               3.6.1
setuptools             40.4.3
six                    1.11.0

要检查是否已将其安装到正确的Python版本,请使用pip -V.为了确保将其安装到正确的副本(虚拟副本或原始副本),请查看软件包安装的文件路径:

To check if you installed it to the right version of Python, use pip -V. To make sure you installed it to the right copy (virtual or original), look at the file path where the package was installed:

PS C:\Users\Ryan> pip -V

结果:

pip 18.0 from c:\users\ryan\appdata\local\programs\python\python37\lib\site-packages\pip (python 3.7)

例如,在我的系统中,它在文件夹路径中显示python37,因此将其安装到我拥有的原始Python 3.7.0安装中,而不是旧版本或虚拟环境(conda等).

For example, in my system, it shows python37 in the folder path, so it installed it to the original Python 3.7.0 installation I have, instead of an older version or virtual environment (conda or virtualenv, etc).

要使用Python可执行文件而不是pip来检查版本:

To check the version using the Python executable, instead of pip:

PS C:\Users\Ryan> py -V
Python 3.7.0

如果您需要将其安装到比默认安装版本更高或更高的Python版本,请使用-在命令中插入版本号作为选项(也称为"switch").例如,要选择版本3.6:

If you need to install it to an older or newer Python version than the default installation, insert the version number as an option (aka. "switch") in the command, using -. For example, to select version 3.6:

py -3.6 -m pip install mysql-connector-python

-可在Windows和类似Unix的操作系统上使用.

The - works on both Windows and Unix-like OSs.

这篇关于适用于python 3.7的MySQL软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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