1

It's probably something quite easy but I can't figure out why my script won't work. I'm trying to make a connection with my sqlite3 database but eclipse returns the error: "Undefined variable from import: connect". I'm running python 3.3 in a virtualenv on linux. Thanks for your help!

from urllib.request import urlopen
import datetime
import sqlite3

class Crawler():

    def storeContent(self, html, url):
        conn = sqlite3.connect('database.db')
        c = conn.cursor()
        c.execute("INSERT .. ", [item, item])
        c.commit()
        c.close()
9
  • Normally, connect is one of the functions that gets imported from _sqlite3 and re-exported from sqlite3. So, the first thing I'd try is: import _sqlite3. If that works, call help(_sqlite3) or dir(_sqlite3) and see if they look right. Commented Jun 18, 2013 at 23:06
  • Also, try importing other C-implemented modules. You might have somehow ended up with a venv with a 32-bit Python but 64-bit libs, or something else that would break all C modules. Commented Jun 18, 2013 at 23:07
  • I think import sqlite3 is correct because when i try print(sqlite3.version_info) it returns correctly the version. The libs I haven't checked yet. Commented Jun 18, 2013 at 23:28
  • 1
    Look at my comment again. _sqlite3, with the underscore, is a C extension module. sqlite3, without the underscore, is a pure-Python module that wraps up that extension module. Please try the tests I suggested on the one with the underscore. For testing other C extension modules… in 3.3, most of these are wrapped up the same way as sqlite3, but there are a few that haven't been. I believe import audioop; print audioop.__file__ should show a .so/.dll/.pyd file, not a .py file. Commented Jun 18, 2013 at 23:37
  • When I try to do: import _sqlite3 it says to be a unresolved import. Does this mean the libaries are incorrect? The audioop returns a non .py file like you said. Sorry for my ignorance, im a beginner Commented Jun 19, 2013 at 11:36

1 Answer 1

1

It seems like Alex Barcelo resolved this issue here.

What worked for me on Ubuntu was almost the same*:

cd /usr/lib/python2.7/lib-dynload/ 
sudo ln -s _sqlite3.x86_64-linux-gnu.so _sqlite3.so

After that, I had to reconfigure the Python Interpreter for my PyDev project: Project Properties -> PyDev-Interpreter/Grammar -> Click here to configure an interpreter not listed, then delete, run auto-config for the python environment you're using, and hit "Apply".

*Replace "python2.7" with the version of python you're using sqlite3 with, and if "_sqlite3.x86_64-linux-gnu.so" is not the right name of the file for your linux system, you can normally search for it using "locate _sqlite3"

Sign up to request clarification or add additional context in comments.

2 Comments

In case you're around. I have the same problem but in virtualenv. How can I solve the issue?
@VictorHerasmePerez, sorry, no idea really. I think my solution would work assuming you have root access, but I suppose you ether tried this or don't have root access.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.