sqlalchemy create_engine function not working while running from file but it work fine in python shell so cannot found the issue. So please anybody point out the issue. I am user window 10 and python version 3.5.3.
Here is the error while running script file:
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
here is the actual code
from sqlalchemy import create_engine
engine =create_engine('mysql+mysqldb://username:password@localhost:3306/databasename')
connection = engine.connect() result = connection.execute('select *
from cuser')
this code work fine if i type this code line by line in python shell but while try to run the file it shows above error.
This is because your have a file on your working directory named sqlalchemy.py. Following the documentation, when importing a module, python looks in CWD before trying the directories from the $PYTHONPATH. And I guess your have no create_engine
in C:/Users/Lenovo/Desktop/Auto/pythonseltest/Tests/sqlalchemy.py
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With