简体   繁体   中英

cx_Oracle not recognized by python

UPDATE: Exact solution is in the comments below the marked answer.


In an enterprise redhat linux environment, Python cannot seem to find the cx_Oracle package needed to connect to the database. See the logs:

[user@redhat ~]$ echo $PYTHONPATH
~/.local/lib/python3.4/site-packages
[user@redhat ~]$ cd $PYTHONPATH
[user@redhat site-packages]$ ls -l
total 1912
drwxrwxr-x  2 user user     131 Apr 20 12:00 cx_Oracle-6.2.1.dist-info
-rwxrwxr-x  1 user user 1900997 Apr 20 12:00 cx_Oracle.cpython-34m.so
-rw-rw-r--  1 user user     290 Apr 20 12:00 easy-install.pth
drwxrwxr-x  4 user user     114 Apr 20 12:00 et_xmlfile
drwxrwxr-x  2 user user     117 Apr 20 12:00 et_xmlfile-1.0.1-py3.4.egg-info
drwxrwxr-x  2 user user     150 Apr 20 12:00 jdcal-1.4.dist-info
-rw-rw-r--  1 user user   12553 Apr 20 12:00 jdcal.py
-rw-rw-r--  1 user user   13386 Apr 20 12:00 jdcal.pyc
drwxrwxr-x 21 user user    4096 Apr 20 12:00 openpyxl
drwxrwxr-x  2 user user     154 Apr 20 12:00 openpyxl-2.5.3-py3.4.egg-info
drwxrwxr-x  2 user user      61 Apr 23 12:00 __pycache__
-rw-rw-r--  1 user user    2389 Apr 23 12:00 site.py
-rw-rw-r--  1 user user    1743 Apr 23 12:00 site.pyc
[user@redhat site-packages]$ python
Python 2.7.5 (default, May  3 2017, 07:55:04)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-14)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named cx_Oracle
>>> import openpyxl
openpyxl/xml/__init__.py:15: UserWarning: The installed version of lxml is too old to be used with openpyxl
  warnings.warn("The installed version of lxml is too old to be used with openpyxl")
>>> exit()
[user@redhat site-packages]$

Please note that both cx_Oracle and openpyxl were both installed using pip in a single command: pip install --user cx_Oracle openpyxl They are both in the same location and pulled into python in the same manner, yet openpyxl is seen and cx_Oracle is not. What am I doing wrong here?

You appear to be running Python 2.7, but the cx_Oracle you installed is for Python 3.4! cx_Oracle is a pure C module so will only work in the Python it was compiled for. The other module (openpyxl) has pure Python modules so it will at least partially load. You'll need to run Python 3.4 or re-install both modules for Python 2.7.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM