Search code examples
pythonpydev

PyDev - unresolved import only on IDE, still running


I'm trying to understand what PyDev doesn't like. I'm under Ubuntu and it seems that PyDev doesn't see the libraries like bash does. I have a problem with two libraries, sqlite3 and peewee. If I run my program on a shell, all fine; if I open it in my newly installed PyDev I see a couple of instruction underlined with the message

Unresolved import: sqlite3

And

Undefined variable from import: get

The first error comes from the following code:

from pprint import pprint
import sqlite3
from bs4 import BeautifulSoup
import codecs
from database import Tbrecipe
from datetime import datetime
import logging

def main():
    logger = logging.getLogger('peewee')
    logger.setLevel(logging.DEBUG)
    logger.addHandler(logging.StreamHandler())
    CONN = sqlite3.connect('ent.db')  

The import error happens at the.. import. Second line.This happens because I've personally added /usr/lib/python2.7/sqlite3 to the pythonpath on the pydev's python interpreter. If I remove it, the error is at "sqlite3.connect". I suppose connect is not defined on that directory. I didn't find it.

Peewee has other issues. I created an object class for my database's table. All fine until I try to use some methods inherited from peewee.

My database.py looks like this:

from peewee import * database = MySQLDatabase('test', **{'host': 'localhost', 'password': 'rt', 'user': 'rt','charset':'utf8mb4'})

class UnknownField(object): def init(self, *_, **__): pass

class BaseModel(Model): class Meta: database = database

class Tbitem(BaseModel): source = IntegerField() name = CharField(null=True)

on my main.py

...
from database import Tbitem
item = Tbitem.get(Tbitem.id==id_item)

both "get" and "Tbitem.id" are underlined in red with the error

Undefined variable from import: get

I can continue to work as nothing happens, or I can go back to vim or vscode (slow debugger), but I"d prefer using this since I'm used to eclipse and I like the idea of pydev. What should I do? I did check pythonpath on a shell and it looks the same, other than a directory that doesn't exist anymore.

I read on the FAQ of pydev that it doesn't like softlinks. Should I remove all softlinks? peewee is not softlinked and sqlite3 I don't even know where it finish.

Anyone with similar issues and a solution? I did read most of the questions here on SO, but they don't work for me.


Solution

  • I solved it by forcing the build of all external libraries that caused that error (force builtins under interpreter's properties) For my libraries I deleted all .pyc files and tried again and it worked.