我已经用python2编写了一个代码,现在我想在python3中执行它,我得到

2022-12-01 05:21:12 发布

您现在位置:Python中文网/ 问答频道 /正文

from sqlalchemy import create_engine
        import pymysql
        import pandas as pd
        db='mysql+pymysql://developer:11111@192.168.1.11:3306/pos'
        db_connection=create_engine(db)
        df=pd.read_sql_table(table_name='product2', con=db_connection)
        #df1=pd.read_sql_table(table_name='product', con=db_connection)
        start_date = '2009-10-19 00:00:00'
        end_date = '2010-10-19 23:59:59'
        mask = (df['DateCreated'] > start_date) & (df['DateCreated'] <= end_date) #DateFilter
        df = df.loc[mask]
        t_type=(df['TherapyType']=='C')
        df = df.loc[t_type]
        df


     i am getting this error :-

            ModuleNotFoundError                       Traceback (most recent call last)
            <ipython-input-1-5c4885ab0640> in <module>
                  1 #extract the data from the created table in which dataframe was inserted..
            ----> 2 from sqlalchemy import create_engine
                  3 import pymysql
                  4 import pandas as pd
                  5 db='mysql+pymysql://developer:devdev@192.168.1.44:3306/pos'

            ModuleNotFoundError: No module named 'sqlalchemy'

我已经用Python2编写了一个代码,我想用Python3执行这个代码,但是我遇到了一个错误,我不知道我应该怎么做


Tags: fromimportpandasdfdbdatesqlalchemyascreatemysqltableconnectionenginepdpymysql
1条回答
网友
1楼 · 发布于 2022-12-01 05:21:12
sudo pip3 install sqlalchemy,

sudo pip3 install PyMySQL,

我使用这两个命令安装了sqlalchemypymysql,现在没有任何错误