php无法通过python连接到mysql

8tntrjer  于 2021-06-20  发布在  Mysql
关注(0)|答案(2)|浏览(405)

我正在写一个php来执行一个python脚本,它像这样连接到mysql

<?php
    echo shell_exec('python doSmt.py 2>&1');
</body></html>")
?>

在python脚本中:


# -*- coding: utf-8 -*-

import mysql.connector

得到这个错误
回溯(最近一次调用last):import mysql.connector importerror中的文件“dosmt.py”,第2行:没有名为mysql.connector的模块
请帮忙
更新:我尝试从netbeans检查安装在phpweb服务器上的包


# -*- coding: utf-8 -*-

import pkg_resources
installed_packages = pkg_resources.working_set
installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
     for i in installed_packages])
print(installed_packages_list)

得到这个了吗
'altgraph==0.10.2','backports ==0.5','bdist mpkg==0.5.0','bonjour py==0.3','certifi==2018.4.16','chardet==3.0.4','click==6.7','flask==1.0.2','futures==3.2.0','idna==2.7','itsdangerous==0.24','jinja2==2.10','macholib==1.5.1','markupsafe==1.0','matplotlib==1.3.1','modulegraph==0.10.4','nose==1.3.7','numpy==1.8.0rc1',','pip==10.0.1','py2app==0.7.3','pyobjc core==2.5.1','pyobjc framework accounts==2.5.1','pyobjc framework addressbook==2.5.1','pyobjc framework applescriptkit==2.5.1','pyobjc framework applescriptobjc==2.5.1','pyobjc framework automator==2.5.1','pyobjc framework cfnetwork==2.5.1','pyobjc framework cocoa==2.5.1','pyobjc framework collaboration==2.5.1','pyobjc framework coredata==2.5.1','pyobjc framework corelocation==2.5.1','pyobjc framework coretext==2.5.1','pyobjc framework dictionaryservices==2.5.1','pyobjc framework exceptionhandling==2.5.1','pyobjc framework fsevents==2.5.1','pyobjc framework inputmethodkit==2.5.1','pyobjc framework installerplugins==2.5.1','pyobjc framework instantmessage==2.5.1','pyobjc framework latentsemanticmapping==2.5.1','pyobjc framework launchservices==2.5.1','pyobjc framework message==2.5.1','pyobjc framework opendirectory==2.5.1','pyobjc framework preferencepanes==2.5.1','pyobjc framework pubsub==2.5.1','pyobjc framework qtkit==2.5.1','pyobjc framework quartz==2.5.1','pyobjc framework screensaver==2.5.1','pyobjc framework scriptingbridge==2.5.1','pyobjc framework searchkit==2.5.1','pyobjc framework servicemanagement==2.5.1','pyobjc framework social==2.5.1',','pyobjc framework systemconfiguration==2.5.1','pyobjc framework webkit==2.5.1','pyopenssl==0.13.1','pyparsing==2.0.1','python dateutil==1.5','python==2.7.10','pytz==2013.7','requests==2.19.1','scipy==0.13.0b1','setuptools==18.5','singledispatch==3.4.0.3','six==1.4.1','tornado==5.0.2','urllib3==1.23','werkzeug==0.14.1','wheel==0.31.1','wsgiref==0.1.2','xattr==0.6.4','zope.interface==4.1.1'
没有与mysql相关的包。我想这就是问题所在。但如何解决这个问题呢?

r7s23pms

r7s23pms1#

好像你还没有安装 mysql.connector . 尝试用pip安装它。

fbcarpbf

fbcarpbf2#

确保dosmt.py文件的第一行中有以下文本:


# !/usr/bin/env python

相关问题