Author |
Topic |
|
rkpara10
United Kingdom
7 Posts |
Posted - 12/31/2020 : 10:17:58 AM
|
Hello,
I managed to install a python package called 'apsw-wheels' on Embedded Python using the 'Connectivity > Python Packages...' option in OriginPro. The 'apsw-wheels or apsw' is a Python wrapper for the SQLite embedded relational database engine. Then, I created the following script in Jupyter notebook. -------------------------------------------------------------------- import apsw
### Opening/creating database
con=apsw.Connection("db_file") cursor=con.cursor() -------------------------------------------------------------------- The above script worked fine in Jupyter Notebook. However, when I tested the above script using the Code Builder (Embedded Python) option in OriginPro, I got the following error.
-------------------------------------------------------------------- Traceback (most recent call last): File "<string>", line 6, in <module> File "D:\kaibasheer\Documents\OriginLab\User Files\apsw.py", line 5, in <module> con=apsw.Connection("db_file") AttributeError: module 'apsw' has no attribute 'Connection' --------------------------------------------------------------------
Before I spend time to investigate the above issue, I would like to know, the current version of Embedded Python in OriginPro supports SQL database?
Thanks, Raees
Origin Ver. and Service Release (Select Help-->About Origin): 2021 Operating System: Windows 10 HOME |
Edited by - rkpara10 on 12/31/2020 1:50:57 PM |
|
Castiel
343 Posts |
Posted - 12/31/2020 : 10:37:31 AM
|
quote: Originally posted by rkpara10
Hello,
I managed to install a python package called 'apsw-wheels' on Embedded Python using the 'Connectivity > Python Packages...' option in OriginPro. The 'apsw-wheels or apsw' is a Python wrapper for the SQLite embedded relational database engine. Then, I created the following script in Jupyter notebook. -------------------------------------------------------------------- import apsw
### Opening/creating database
con=apsw.Connection("db_file") cursor=con.cursor() -------------------------------------------------------------------- The above script worked fine in Jupyter Notebook. However, when I tested the above script using the Code Builder (Embedded Python) option in OriginPro, I got the following error.
-------------------------------------------------------------------- Traceback (most recent call last): File "<string>", line 6, in <module> File "D:\kaibasheer\Documents\OriginLab\User Files\apsw.py", line 5, in <module> con=apsw.Connection("db_file") AttributeError: module 'apsw' has no attribute 'Connection' --------------------------------------------------------------------
Before I spend time to investigate the above issue, I would like to know, the current version of Embedded Python in OriginPro supports SQL database?
Thanks, Raees
Origin Ver. and Service Release (Select Help-->About Origin): 2021 Operating System: Windows 10 HOME
Rename your file. Do not name it as 'apsw'.
------------------------------------------
Be The Change
You Want To See
In The World
------------------------------------------
|
|
|
rkpara10
United Kingdom
7 Posts |
Posted - 12/31/2020 : 1:38:53 PM
|
Hi Castiel,
Thanks for your suggestion. But, it's not working for me.
For simplifying my above question, I have recreated the above experiment using 'sqlite3' python package and the code is provided below.
-------------------------------------------------------------------- import sqlite3 ### Opening/creating database con = sqlite3.connect('db_file') cursor=con.cursor() -------------------------------------------------------------------- Again, the above script worked fine using Jupyter Notebook. However, when I tested the above script using the Code Builder (Embedded Python) option in OriginPro, I got the following error. -------------------------------------------------------------------- #Error Traceback (most recent call last): File "<string>", line 6, in <module> File "D:\kaibasheer\Documents\OriginLab\User Files\TestPackages.py", line 3, in <module> con = sqlite3.connect('db_file') sqlite3.OperationalError: unable to open database file --------------------------------------------------------------------
I am wondering, do you know the Embedded Python in OriginPro support SQL database?
Any suggestion from Originlab Technical Support would also be appreciated.
Regards, Raees |
|
|
cpyang
USA
1406 Posts |
Posted - 12/31/2020 : 2:45:15 PM
|
I don't see error. Here is what I did
1. download sample SQLite from https://www.sqlitetutorial.net/sqlite-sample-database/
2. place chinook.db to UFF, as that is where my py file will be
3. open Untitled.py from Connectiviy menu and put the code
import sqlite3
con = sqlite3.connect('chinook.db')
print(con)
cursor=con.cursor()
print(cursor)
I got <sqlite3.Connection object at 0x000001D502B4FE40> <sqlite3.Cursor object at 0x000001D502C5AB20>
sqlite3 was included into Python so there is no need to install it. Maybe you can remove apsw that you installed? Maybe that messed things up.
CP
|
|
|
Castiel
343 Posts |
Posted - 12/31/2020 : 5:56:00 PM
|
quote: Originally posted by rkpara10
Hi Castiel,
Thanks for your suggestion. But, it's not working for me.
For simplifying my above question, I have recreated the above experiment using 'sqlite3' python package and the code is provided below.
-------------------------------------------------------------------- import sqlite3 ### Opening/creating database con = sqlite3.connect('db_file') cursor=con.cursor() -------------------------------------------------------------------- Again, the above script worked fine using Jupyter Notebook. However, when I tested the above script using the Code Builder (Embedded Python) option in OriginPro, I got the following error. -------------------------------------------------------------------- #Error Traceback (most recent call last): File "<string>", line 6, in <module> File "D:\kaibasheer\Documents\OriginLab\User Files\TestPackages.py", line 3, in <module> con = sqlite3.connect('db_file') sqlite3.OperationalError: unable to open database file --------------------------------------------------------------------
I am wondering, do you know the Embedded Python in OriginPro support SQL database?
Any suggestion from Originlab Technical Support would also be appreciated.
Regards, Raees
con = sqlite3.connect('db_file')
Where is the db_file located? Is 'db_file' the full path?
------------------------------------------
Be The Change
You Want To See
In The World
------------------------------------------
|
|
|
rkpara10
United Kingdom
7 Posts |
Posted - 01/04/2021 : 12:45:19 PM
|
Hello Cpyang and Castiel,
Thank you both for your suggestions, and the modified code below is working.
I did the following; 1. Uninstalled 'apsw' package 2. Provided an explicit path to .db file
Code: import sqlite3 con = sqlite3.connect('D:/kaibas/Documents/OriginLab/User Files/chinook.db') print(con) cursor=con.cursor() print(cursor)
Output: <sqlite3.Connection object at 0x000001AA017D15D0> <sqlite3.Cursor object at 0x000001AA0194B0A0>
Thanks, Raees |
|
|
|
Topic |
|
|
|