Recognizing cx_Oracle install within PyDev
Asked Answered
S

1

8

I am on Windows 10 Pro 64-bit Anniversary Edition using Python 3.5.2 (Anaconda 4.1.1). I download the latest Oracle 12c Instant Client instantclient-basic-windows.x64-12.1.0.2.0.zip and instantclient-sdk-windows.x64-12.1.0.2.0.zip into C:\instantclient and put C:\instantclient on my PATH. Then I download the installer cx_Oracle-5.2.1-12c.win-amd64-py3.5.exe directly from PyPI.

Now I can start an Anaconda python prompt and type import cx_Oracle and it is successful.

>>> import cx_Oracle
>>>

By when I go into my PyDev installation on Eclipse Neon (4.6), the import cx_Oracle line in my source file still shows an error as an unresolved import.

  • I went into Windows > Preferences > PyDev > Interpreters > Python Interpreter and removed the Anaconda interpreter (C:\bin\anaconda3\python.exe) and added it back. I restarted Eclipse, but no luck.
  • I issued a Project > Clean on all my projects and restarted Eclipse. It still shows import cx_Oracle as an unresolved import.

How can I get PyDev to see my cx_Oracle package installation?

Note that there are a lot of supposed answers that do not work for me; I've tried all the suggestions, as indicated above.

Spunky answered 19/9, 2016 at 19:0 Comment(14)
can you do import sys; print(sys.executable) in both consoles (anaconda and eclipse) to be sure your setting has an effect?Vaenfila
They both say C:\bin\anaconda3\python.exe. (I had no idea that PyDev had an interactive console---very neat. Thank for the tip.)Spunky
I didn't know either, but I guessed that existed :) Well, weird. Once imported, can you print(cx_Oracle.__file__) to see where it is located?Vaenfila
It says cx_Oracle is installed in C:\bin\anaconda3\lib\site-packages\cx_Oracle.cp35-win_amd64.pyd.Spunky
sorry to ask this but can you type import cx_Oracle in the pydev console (now that you know there's one), respecting the case, and see what happens (getting desperate here)Vaenfila
I already did import cx_Oracle within the pydev console --- that's how I was able to print(cx_Oracle.__file__) as you requested above. :)Spunky
I do not have another python installed.Spunky
can you post a screenshot or something showing the error?Vaenfila
There is nothing to see! It's a red, squiggly line under the import, and Ctrl+Click on it takes me nowhere. Here, see this screen shot: https://mcmap.net/q/1471714/-pydev-does-not-recognize-imports/421049Spunky
that looks a lot like a duplicate of your question, except... that it doesn't work! Have you tried to set another workspace? (last suggestion from me :))Vaenfila
My advise to you is to get off of Eclipse. PyCharm is better an IDE dedicated to Python but I'm no fan of using an IDE for Python. As you've witnessed they just get in the way.Ultann
@GarretWilson comments is correct. Why, i check setup.py in related module and see default python directory check function. You need add Anaconda path name to SYS ENV or vice versa... Or copy/softlink related module to Anaconde library directory.Vernalize
I have the same problem with Eclipse. I noticed that cx_Oracle is only represented by library file cx_Oracle.cp35-win_amd64.pyd in site-packages after installation and has no stub. I never had problems with running the programs though.Calesta
Just went back to PyDev: After adding cx_Oracle to the forced built-ins the problem goes away. Preferences / PyDev / Interpreters / Python Interpreter / Tab "Forced Builtins"Calesta
C
4

You can try this (after the steps that you already report in your question)

  1. Check if the installation in PyDev is ok (besides showing an error marker for import cx_Oracle)

    import cx_Oracle
    
    conn = cx_Oracle.connect('hr/hr@pdborcl')
    cur = conn.cursor()
    cur.execute('select 13 from dual')
    for r in cur.fetchall():
        print(r)
    

    If this works, and prints (13,) the installation is correct. Likely some part of completion could work as well. In addition, Shift+Click on cx_Oracle should report The definition of ... was found at ....

  2. Go to Windows > Preferences > PyDev > Interpreters > Python Interpreter and on the tab Forced builtins add cx_Oracle

    After rebuilding the project, the error markers on the import should go away. (In the little test program I just did a trivial edit and saved.)

For the record:

Eclipse Version: 4.6.0 (Neon)
PyDev Version: 5.2.0
Python: 3.5.2 (from a virtualenv)
Calesta answered 29/9, 2016 at 19:15 Comment(8)
On conn = cx_Oracle.connect('hr/hr@pdborcl') I get: cx_Oracle.DatabaseError: ORA-12154: TNS:could not resolve the connect identifier specifiedSpunky
@GarretWilson: You will need to replace the connection string with something that works on your system. The syntax is the same as the connection string for SQL*Plus. Format <user>/<password>@<tnsname>Calesta
But I don't need or want to connect to a database on this platform. I just want the links to show up without errors and be able to click on them to view source.Spunky
Sorry for the misunderstanding then: The first step just serves to confirm that the installation is correct. To remove the error marker: Step 2Calesta
@GarretWilson: Another thing: You will not be able to view the source, because the extension is not written in Python. The installed file is in fact a DLL (named PYD). Auto-completion works to some extent.Calesta
Following your second step (adding cx_Oracle as a "forced builtin") took away the error for the import. But as you predicted I still can't browse the source --- I get an error "The definition was found at …\cx_Oracle.cp35-win_amd64.pyd (which cannot be opened because it is a compiled extension)". But I can't compile it from source because it can't find vcvarsall.bat, blah blah blah. So there was no point in my installing the cx_Oracle library in the first place if I just wanted to browse the source. (Things like this make me miss Java so much.)Spunky
Let us continue this discussion in chat.Calesta
I don't know of anything else that needs discussing. Thanks for your response. I've awarded you the bounty.Spunky

© 2022 - 2024 — McMap. All rights reserved.