Menu ▾ ▴

Code completion for MySQLdb and minidom

yanfei liu
2008-10-10
2013-03-15
  • yanfei liu

    yanfei liu - 2008-10-10

    1) import MySQLdb
    db=MySQLdb.???
    :: code completion did not work, after input "MySQLdb."
    :: python has install MySQLdb lib

    2) from xml.dom import minidom
    xmldoc=minidom.parse("\home\t.xml")
    xmldoc.???
    :: code completion did not work, after input xmldoc.

    Can you help to explain the reason?

     
    • Fabio Zadrozny

      Fabio Zadrozny - 2008-10-10

      Usually, that happens when the static analysis is not able to gather enough information to display you this info.

      A common approach to solve that is adding the packages you want to the 'forced builtins': http://fabioz.com/pydev/manual_101_interpreter.html (which in this case would mean adding 'xml' and 'MySQLdb' to that list), so that it tries to gather that info from a shell instead of only trying the static analysis.

      Cheers,

      Fabio

       
    • Anonymous

      Anonymous - 2009-09-06

      What does the line "python has install MySQLdb lib" mean specifically.  I'm having a problem even getting python to import MySQLdb in eclipse (with PyDev) even though "import MySQLdb" works fine at the command line.  I've tried adding "MySQLdb" to the Forced Builtins with no luck.  Here's a dump of my interpreterInfo.py if that helps.
      thanks

      Momiji:PySrc brian$ python interpreterInfo.py                                   Version2.6
      EXECUTABLE:/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python|
      |/Applications/eclipse/plugins/org.python.pydev_1.4.8.2881/PySrcOUT_PATH
      |/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6INS_PATH
      |/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynloadINS_PATH
      |/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-oldINS_PATH
      |/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tkINS_PATH
      |/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwinINS_PATH
      |/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-macINS_PATH
      |/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackagesINS_PATH
      |/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packagesINS_PATH
      |/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/MySQL_python-1.2.3c1-py2.6-macosx-10.3-fat.eggINS_PATH
      |/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/setuptools-0.6c9-py2.6.eggINS_PATH
      |/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zipINS_PATH
      @
      $
      |__builtin__
      |__main__
      |_ast
      |_codecs
      |_sre
      |_symtable
      |_warnings
      |errno
      |exceptions
      |gc
      |imp
      |marshal
      |posix
      |pwd
      |signal
      |sys
      |thread
      |xxsubtype
      |zipimport
      Traceback (most recent call last):
        File "interpreterInfo.py", line 138, in <module>
          raise RuntimeError('Ok, this is so that it shows the output (ugly hack for some platforms, so that it releases the output).')
      RuntimeError: Ok, this is so that it shows the output (ugly hack for some platforms, so that it releases the output).

       
      • Fabio Zadrozny

        Fabio Zadrozny - 2009-09-07

        Does MySQLdb work when you call from a python script inside eclipse? This usually means your pythonpath is not correct. Where is MySQLdb installed?

        If it works from the command line, you can probably do:
        import MySQLdb
        print MySQLdb.__file__

        and add the dir that contains that file to your pythonpath.

        Cheers,

        Fabio

         
  • Laurie Tynor

    Laurie Tynor - 2010-03-12

    Was this issue resolved?  I am seeing the same problem:

    Eclipse 3.5.2, Pydev 1.5.5, Python 2.6.4, Windpws XP SP3

    - Pydev installed by putting it in the dropins directory
    - Downloaded the binary for MySQLdb from here: http://www.codegood.com/

    1.  Python command-line processor finds MySQLdb fine - the import MySQLdb works and I can run the db-api methods
    2.  Python interpretor run inside of eclipse using the PyDev Python console finds MySQLdb fine  and the autocomplete even works from there
    3.  PyDev editor window cannot find MySQLdb - the import has an Unresolved Import error, and because of this none of the autocompletes work.  I can still enter in the rest of the MySQLdb functions, and even run from the editor window with the RunAs Python Run.   But I can't make the editor find the MySQLdb module.

    The egg is already decompressed (the windows installer did this).  The directory structure under site-packages looks like this: 
          site-packages/MySQL_python-1.2.2-py2.6.egg-info/   
         site-packages/MySQLdb/  
        _mysql.pyd,
        _mysql_exceptions.py
        _mysql_exceptions.pyc
        _mysql_exceptions.pyo

    If I look at my Python project (that the editor can't find MySQLdb for) - I can look under the Python.exe in the Pydev Package Explorer, and under System Libs I do see site-packages/MySQLdb (as a source folder) and site-packages/MySQL_python-1.2.2-py2.6.egg-info (as a folder), plus the _mysql.pyd and _mysql_exceptions.py files

    If I run MySQLdb.__file__ in both my command-line Python interpreter, and the PyDev's interactive console in Eclipse, I get the directory containiing the MySQLdb folder metioned above (site-packages)

    I have tried the following, none of it worked:
    1.  PythonPath->External Libraries -> Add source folder - pointing to the site-packages/MySQLDB directory (this is what the MySQLdb.__file__ prints out in the console)
    2.  PythonPath->External Libraries -> Add source folder - pointing to the site-packages directory
    3.  PythonPath->External Libraries -> Add zip/jar/egg - pointing to the site-package/MySQLDB directory (didn't expect this to work since the egg is uncompressed, but I figured it was worth a try)
    4.  Creating a new PyDev project for the MySQLDB directory and making my original Python project refer to it (I saw a reference on the web saying to try this)

    If this issue was resolved, please let me know.   I am a Python newbie, and I do not know how to rebuild the original egg properly from the exploded directory structre that the windows installer made.  If the resolution requires this, then I need to also ask you to please let me know how to recreate the egg.

    Thank you for any help with this - I really like PyDev, and would like to use it as my IDE going forward.

    Laurie Tynor

     
  • Laurie Tynor

    Laurie Tynor - 2010-03-12

    Well, after that long posting saying that I couldn't get it to work…   I just did.   It was user-error; your answers above did work just fine.

    1.  I added the library using Windows-Preferences (instead of the project-specific Properties->External libraries)
    2.  I added MySQLdb to the Windows->Preferences ForcedBuiltIns listing 
    3.  I removed my project and recreated a new one from scratch - and on the import MySQLdb works and the autocomplete does as well.

    Sorry for the above long posting,  but thank you for your previous patient replies (that did work)

    Laurie Tynor