2024-04-26 05:14:08 发布
网友
我按照程序安装了MySQL for python。当我试图在python中导入MySQLdb时,会出现一个错误。在
import MySQLdb Traceback (most recent call last): File "", line 1, in File "MySQLdb/init.py", line 19, in import _mysql ImportError: No module named _mysql
set the ^{} environment variable so that it includes the path to the MySQL libraries.
因此,在您的.bash_配置文件(.bashrc,.profile取决于您使用的是哪一个)添加一行如下:
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
(/usr/local/mysql/lib是MySQL库的路径,在您的系统中可能有所不同)
/usr/local/mysql/lib
使用pip进行包管理和导入,然后运行:
pip install MySQL-python
在代码中,您应该使用以下命令在顶部导入库:
请参阅https://github.com/farcepest/MySQLdb1/blob/master/doc/user_guide.rst以获取有关包使用的更多详细信息。在
请参阅http://www.pip-installer.org/en/latest/以获取有关pip的更多详细信息。在
这也是关于包/环境管理的最佳实践的一本好书 https://python-guide.readthedocs.org/en/latest/
set the ^{} environment variable so that it includes the path to the MySQL libraries.
因此,在您的.bash_配置文件(.bashrc,.profile取决于您使用的是哪一个)添加一行如下:
(
/usr/local/mysql/lib
是MySQL库的路径,在您的系统中可能有所不同)使用pip进行包管理和导入,然后运行:
在代码中,您应该使用以下命令在顶部导入库:
^{pr2}$请参阅https://github.com/farcepest/MySQLdb1/blob/master/doc/user_guide.rst以获取有关包使用的更多详细信息。在
请参阅http://www.pip-installer.org/en/latest/以获取有关pip的更多详细信息。在
这也是关于包/环境管理的最佳实践的一本好书 https://python-guide.readthedocs.org/en/latest/
相关问题 更多 >
编程相关推荐