[英]Troubles installing mysqlclient with pip3
I'm trying to set up a python 3.6 environment with Django. The installation instructions say I should install mysqlclient to be able to connect to mySQL. I get this:我正在尝试使用 Django 设置 python 3.6 环境。安装说明说我应该安装 mysqlclient 才能连接到 mySQL。我明白了:
dennis@django:~$ sudo -H pip3 install mysqlclient
Collecting mysqlclient
Using cached mysqlclient-1.3.10.tar.gz
Complete output from command python setup.py egg_info:
/bin/sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-4jiw3hvk/mysqlclient/setup.py", line 17, in <module>
metadata, options = get_config()
File "/tmp/pip-build-4jiw3hvk/mysqlclient/setup_posix.py", line 44, in get_config
libs = mysql_config("libs_r")
File "/tmp/pip-build-4jiw3hvk/mysqlclient/setup_posix.py", line 26, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
OSError: mysql_config not found
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-4jiw3hvk/mysqlclient/
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
mySQL is properly installed. mySQL 已正确安装。 What should be in the mysql_config file?
mysql_config 文件中应该包含什么? When I try to upgrade pip3 I get this:
当我尝试升级 pip3 时,我得到了这个:
dennis@django:~$ sudo -H pip3 install --upgrade pip3
Collecting pip3
Could not find a version that satisfies the requirement pip3 (from versions: )
No matching distribution found for pip3
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
After installing mysqlclient with pip3, I noticed that the module was installed in the python3.5 directory instead of in the python3.6 directory so when I tried to import the MySQLdb module running python3.6, it was not found使用 pip3 安装 mysqlclient 后,我注意到该模块安装在 python3.5 目录而不是 python3.6 目录中,因此当我尝试导入运行 python3.6 的 MySQLdb 模块时,找不到它
dennis@django:~/python_db$ python
Python 3.6.0+ (default, Feb 4 2017, 11:11:46)
[GCC 5.4.1 20161202] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'MySQLdb'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 23, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Original exception was:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'MySQLdb'
>>>
I then reran using python 3.5 and it was found.然后我使用 python 3.5 重新运行并找到了。 How do I install modules using pip3 into the 3.6 directory?
如何使用 pip3 将模块安装到 3.6 目录中?
If you're using Mac OS, try this: 如果您使用的是Mac OS,请尝试以下操作:
brew install mysql
If you're using Ubuntu14/16, try this: 如果您使用的是Ubuntu14 / 16,请尝试以下操作:
sudo apt install libmysqlclient-dev
and one more: 还有一个:
pip3 can be updated with sudo pip3 install -U pip
可以使用
sudo pip3 install -U pip
更新sudo pip3 install -U pip
LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysqlclient
In Debian Stretch the required package name seems to have changed to default-libmysqlclient-dev 在Debian Stretch中,所需的软件包名称似乎已更改为default-libmysqlclient-dev
https://packages.debian.org/stretch/default-libmysqlclient-dev https://packages.debian.org/stretch/default-libmysqlclient-dev
如果您在OSX上运行MAMP,请执行以下操作:
export PATH=$PATH:/Applications/MAMP/Library/bin
您可以尝试将mysql安装到特定的python目录,例如w / python 3.6
sudo python3.6 /usr/bin/pip3 install mysqlclient
In my case the issue was solved by doing the following: 就我而言,通过执行以下操作解决了该问题:
sudo aptitude install libmysqlclient-dev
As I was using Python 3.x, the following was also necessary: 当我使用Python 3.x时,还需要执行以下操作:
sudo aptitude install python3-dev
Looking over this old question (while looking for something else), I observe that the problem could be that the directory containing mysql_config
was not in the current $PATH.查看这个老问题(同时寻找其他问题),我发现问题可能是包含
mysql_config
的目录不在当前 $PATH 中。 Apparently that's what the install script uses to try to find it.显然这就是安装脚本用来尝试找到它的内容。 It's possible for "mysql to be installed," but not on the $PATH – or for the $PATH to refer to the wrong version.
有可能“安装 mysql”,但不在 $PATH 上——或者 $PATH 指向错误的版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.