![](/img/trans.png)
[英]issue with nested python module importing when executing imported function itself
[英]Python pandas - Module not imported when executing from php
我有两个 php 脚本。 两者都执行 python3 文件,并且都通过 sendgrid api 发送电子邮件,并设计为 email id 到 mysql 数据库表中。
在其中一个文件中,我通过 php mysqli_query 本身将 email id 写入 mysql。 除此之外,我还发送邮件。 这行得通。 该文件的最初几行如下所示:
import argparse
import os
import sendgrid as sendgrid
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
在第二个文件中,我想做一些数据重新对齐,因此,我使用pandas
和MySQLdb
在写入数据库之前操作数据。 该文件的最初几行如下所示:
import os
import argparse
#import MySQLdb
#import pandas as pd
import sendgrid as sendgrid
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
ap = argparse.ArgumentParser()
ap.add_argument("-f","--inputFile",required=True,help="name of the annotations file")
ap.add_argument("-c","--clientid",required=True,help="name of the operator")
在此脚本中,我收到ModuleNotFoundError: No module named 'MySQLdb'
, pandas
也是如此。 但是,如果我禁用这两个导入,rest 工作正常。
我已经使用以下方法安装了这两个库:
sudo pip3 install pandas
sudo pip3 install mysql-client-dev (not sure about this path, but it works properly)
当我使用sudo pip3 list
和pip3 list
列出包时,我可以看到所有包,包括sendgrid
、 pandas
和mysqlclient
。 当我从 python3 控制台运行时,我可以毫无问题地导入所有 3 个包。
路径中的所有文件都归www-data:www-data
所有,所有文件都拥有 777 权限。 仍然每当我使用import pandas as pd
运行脚本时,我都会收到未找到模块的错误。
通过全局安装 python 软件包解决了这个问题。 要全局安装 python package,例如 pandas,请使用
sudo -H pip3 install pandas
安装后,我的所有程序都立即开始运行。 我的印象是sudo pip3 install pandas
将安装在根级别,因此可以在全球范围内使用,但事实并非如此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.