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.

Community
  • 1
  • 1
Garret Wilson
  • 18,219
  • 30
  • 144
  • 272
  • can you do `import sys; print(sys.executable)` in both consoles (anaconda and eclipse) to be sure your setting has an effect? – Jean-François Fabre Sep 19 '16 at 19:03
  • They both say `C:\bin\anaconda3\python.exe`. (I had no idea that PyDev had an interactive console---very neat. Thank for the tip.) – Garret Wilson Sep 19 '16 at 19:07
  • 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? – Jean-François Fabre Sep 19 '16 at 19:10
  • It says cx_Oracle is installed in `C:\bin\anaconda3\lib\site-packages\cx_Oracle.cp35-win_amd64.pyd`. – Garret Wilson Sep 19 '16 at 19:12
  • 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) – Jean-François Fabre Sep 19 '16 at 19:18
  • 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. :) – Garret Wilson Sep 19 '16 at 19:21
  • I do not have another python installed. – Garret Wilson Sep 19 '16 at 21:20
  • can you post a screenshot or something showing the error? – Jean-François Fabre Sep 19 '16 at 21:26
  • 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: http://stackoverflow.com/q/26235307/421049 – Garret Wilson Sep 19 '16 at 21:30
  • 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 :)) – Jean-François Fabre Sep 19 '16 at 21:38
  • 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. – Dan Sep 29 '16 at 02:28
  • @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. – dsgdfg Sep 29 '16 at 06:05
  • 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. – M. Wymann Sep 29 '16 at 07:41
  • 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" – M. Wymann Sep 29 '16 at 07:48

1 Answers1

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)
M. Wymann
  • 350
  • 2
  • 7
  • On `conn = cx_Oracle.connect('hr/hr@pdborcl')` I get: `cx_Oracle.DatabaseError: ORA-12154: TNS:could not resolve the connect identifier specified` – Garret Wilson Sep 29 '16 at 22:17
  • @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 /@ – M. Wymann Sep 29 '16 at 22:24
  • 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. – Garret Wilson Sep 29 '16 at 22:27
  • Sorry for the misunderstanding then: The first step just serves to confirm that the installation is correct. To remove the error marker: Step 2 – M. Wymann Sep 29 '16 at 22:28
  • @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. – M. Wymann Sep 29 '16 at 22:39
  • 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.) – Garret Wilson Sep 29 '16 at 22:49
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/124596/discussion-between-m-wymann-and-garret-wilson). – M. Wymann Sep 29 '16 at 22:51
  • I don't know of anything else that needs discussing. Thanks for your response. I've awarded you the bounty. – Garret Wilson Sep 29 '16 at 22:55