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

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

在Python脚本中:
# -*- coding: utf-8 -*-
import mysql.connector

得到这个错误
回溯(最近的最后一次调用):文件“doSmt.py”,第2行,在import中
mysql.connector导入错误:没有名为mysql.connector的模块
请帮忙
更新:
我试着从netbeans检查安装在php web服务器上的包
# -*- 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 abc==0.5”,“bdist mpkg==0.5.0”,
'bonjour py==0.3','certifi==2018.4.16','chardet==3.0.4',
'点击==6.7','烧瓶==1.0.2','未来==3.2.0','idna==2.7',
'它的危险性==0.24','金贾2==2.10','马赫利布==1.5.1',
‘markupsafe==1.0’,‘matplotlib==1.3.1’,‘modulegraph==0.10.4’,
'鼻==1.3.7','鼻==1.8.0rc1','皮==10.0.1','皮2app==0.7.3',
“pyobjc core==2.5.1”,“pyobjc framework accounts==2.5.1”,
'pyobjc framework addressbook==2.5.1',
'pyobjc框架applescriptkit==2.5.1',
'pyobjc框架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核心位置==2.5.1',
'pyobjc framework coretext==2.5.1',
'pyobjc框架字典服务==2.5.1',
'pyobjc framework eventkit==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消息==2.5.1',
'pyobjc framework opendirectory==2.5.1',
'pyobjc framework首选项窗格==2.5.1',
“pyobjc framework pubsub==2.5.1”,“pyobjc framework qtkit==2.5.1”,
'pyobjc框架石英==2.5.1',
'pyobjc framework屏幕保护程序==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 syncservices==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”,
“龙卷风==5.0.2”,“urllib3==1.23”,“werkzeug==0.14.1”,
'车轮==0.31.1','wsgiref==0.1.2','xattr==0.6.4',
'zope.interface==4.1.1'
没有与mysql相关的包。我想这就是问题所在。但怎么解决呢?

最佳答案

确保doSmt.py文件的第一行中包含以下文本:

#!/usr/bin/env python

10-08 19:46