PHP无法通过python

时间:2018-07-23 04:01:06

标签: php python mysql webserver

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

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

在Python脚本中:

# -*- coding: utf-8 -*-
import mysql.connector

并得到此错误

  

回溯(最近一次通话最后一次):导入中的文件“ doSmt.py”,第2行   mysql.connector ImportError:没有名为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',   '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-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-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-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',   'wheel == 0.31.1','wsgiref == 0.1.2','xattr == 0.6.4',   'zope.interface == 4.1.1'

没有与mysql相关的软件包。我认为这是问题所在。但是如何解决呢?

2 个答案:

答案 0 :(得分:0)

似乎您尚未安装mysql.connector。尝试使用pip安装它。

答案 1 :(得分:0)

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

#!/usr/bin/env python