python安装pymysql【MAC】

python安装pymysql【MAC】,第1张

1、输入“python3 install pymysql",报错

2、后来使用国内镜像源,还是报错,无法安装。

    pip3 install 库名 -i 镜像源地址

    例如:pip3 install pymysql -i  https://pypi.tuna.tsinghua.edu.cn/simple

    镜像源地址

    清华: https://pypi.tuna.tsinghua.edu.cn/simple

    豆瓣: http://pypi.douban.com/simple/

    阿里: http://mirrors.aliyun.com/pypi/simple/

3、经网上查询,需使用”--trusted-host  pypi.tuna.tsinghua.edu.cn ",可安装成功。

即:pip install 库名 -i 镜像源地址 --trusted-host  pypi.tuna.tsinghua.edu.cn

例如:pip3 install pymysql -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn

4、验证pymysql是否安装成功。

>>>import pymysql   不报错就行。

看懂英文的话,参考一下:

down vote

It's time to be a big boy and install from source. Try this:

1) Download the MySQL-python-1.X.X.tar.gz file(by default will go to your Downloads directory)

2) Open a Terminal window and cd to the Downloads directory.

3) Unzip the file you downloaded:

~/Downloads$ tar xfvz MySQL-python-1.X.X.tar.gz

That will create a directory inside your Downloads directory called MySQL-python

4) cd into the newly created directory.

5) Typically, you just open the file called README or INSTALL and follow the instructions--but generally to install a python module all you do is:

$ sudo python setup.py install

If you care to look, there should be a file called setup.py inside your newly created MySQL-python directory, and you are invoking that program to install the module.

Also note that this:

export PATH=$PATH:/usr/local/mysql/bin

is not permanent if you did that on the command line. You need to put that line in a file called .bashrc in your home directory (~/ or equivalently /Users/YOUR_USER_NAME). To see if .bashrc already exists(it's a hidden file), issue the command:

$ ls -al

and look for .bashrc. If .bashrc doesn't exist, then create it

在mac上用python连接远程mysql数据库需要在本机安装mysql吗

mysql-python 是需要本地安装了mysql才行。你安装的xmapp里面的mysql, mysql-python可能没找到正确的配置。

如果不是生产环境,使用 mysql-connector 替代,这个是 mysql官方推荐的驱动,纯python实现。不需要本地配置本地mysql。使用方法和 mysqldb一样。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/6147578.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-16
下一篇 2023-03-16

发表评论

登录后才能评论

评论列表(0条)

保存