sqlalchemy create_engine函数在从文件运行时不起作用,但它在python shell中工作正常,因此无法找到问题.所以请任何人指出这个问题.我是用户窗口10和python版本3.5.3.
运行脚本文件时出现以下错误:
C:\python\python.exe C:/Users/Lenovo/Desktop/Auto/pythonseltest/Tests/sqlalchemy.py Traceback (most recent call last): File "C:/Users/Lenovo/Desktop/Auto/pythonseltest/Tests/sqlalchemy.py", line 2, in <module>
from sqlalchemy import create_engine File "C:\Users\Lenovo\Desktop\Auto\pythonseltest\Tests\sqlalchemy.py", line 2, in <module>
from sqlalchemy import create_engine ImportError: cannot import name 'create_engine'
Process finished with exit code 1
Run Code Online (Sandbox Code Playgroud)
这是实际的代码
from sqlalchemy import create_engine
engine =create_engine('mysql+mysqldb://username:password@localhost:3306/databasename')
connection = engine.connect() result = connection.execute('select *
from cuser')
Run Code Online (Sandbox Code Playgroud)
这个代码工作正常,如果我在python shell中逐行键入此代码,但在尝试运行该文件时,它显示上面的错误.
| 归档时间: |
|
| 查看次数: |
3196 次 |
| 最近记录: |