Sublime Forum

How to import pyodbc in sublime plugin development

#1

Hi folks,
I am a newbie in sublime plugin development.
I am trying to develop a teradata sql tool plugin by leveraging pyodbc, stuff like this and then parse the sql result in sublime window

import pyodbc 
conn = pyodbc.connect(driver,DBCName, database, uid,pwd)
cursor = conn.cursor()
cursor.execute("select * from table")

After pip install pyodbc, I can run import pyodbc in cmd environment with no problem.


Since where pyodbc installed is in sys.path and python recognize that location

However, in “sublime python” (the python cmd after type ctrl+`), even though I install here

and this path is in sys.path, I still can’t import pyodbc.

I also try to create a dummy python file called test38 here

and in above screenshot, we can see test38.py can be imported.

So does pyodbc with .pyd file extension can’t be import in sublime plugin development or do I miss something here?

Thank y’all so much for the help! :joy:

0 Likes

#2
  1. You downloaded a wrong wheel. pyodbc-4.0.34-cp38-cp38-win_amd64.whl should be used.
  2. Put pyodbc.cp38-win_amd64.pyd under Lib\python38.
  3. Maybe restart ST.
0 Likes

#3

yep that works perfectly! thank you!

0 Likes

#4

That works!
And may I also ask how to set up a build point to 3.8 in sublime text 4? Currently it will automatically build with 3.3.

0 Likes

#5

Build? It just calls py on your machine. https://github.com/sublimehq/Packages/blob/54cfa19ff350c976f5740818961fcc24b653bce4/Python/Python.sublime-build#L9

You have to create your own build system if that’s not what you want.

0 Likes

#6

A .python-version with a content of 3.8 placed in a package’s root directory tells ST to run a plugin with python 3.8 plugin host.

0 Likes