![](/img/trans.png)
[英]SQLAlchemy create_engine not working in Google Cloud Function
[英]sqlalchemy create_engine function not working while running file name testalchemy.py
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
这是实际的代码
from sqlalchemy import create_engine
engine =create_engine('mysql+mysqldb://username:password@localhost:3306/databasename')
connection = engine.connect() result = connection.execute('select *
from cuser')
如果我在python shell中逐行输入此代码,但是在尝试运行文件时,此代码工作正常,它显示上面的错误。
这是因为您的工作目录中有一个名为sqlalchemy.py的文件。 在文档之后 ,在导入模块时,python在尝试$ PYTHONPATH中的目录之前查找CWD。 我想你在C:/Users/Lenovo/Desktop/Auto/pythonseltest/Tests/sqlalchemy.py
没有create_engine
C:/Users/Lenovo/Desktop/Auto/pythonseltest/Tests/sqlalchemy.py
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.