Question

I have installed cx_Oracle to connect Python and Oracle for programming; however, I can only import cx_Oracle into python if I am in the directory where cx_Oracle lives. How can I import cx_Oracle globally? Below is code demonstrating the problem.

Thanks for your help.

Python Can't Import cx_Oracle

user@T420 ~ $ python
Python 2.7.3 (default, Sep 26 2012, 21:51:14) 
[GCC 4.7.2] 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

Python Can Import cx_Oracle from the Directory Where it is Located

user@T420 /usr/lib/python2.7/site-packages $ ls
cx_Oracle-5.1.2-py2.7.egg-info  cx_Oracle.so

user@T420 /usr/lib/python2.7/site-packages $ python
Python 2.7.3 (default, Sep 26 2012, 21:51:14) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
>>> 
Was it helpful?

Solution

Python on Debian does not use the site-packages folder. You can simply move the files into the dist-packages folder and everything should work. The other solution as Aaron mentioned would be to add the path to site-packages into the sys.path folder. However, the python site.py folder says the following:

Quote from site.py file:

For Debian and derivatives, this sys.path is augmented with directories for packages distributed within the distribution. Local addons go into /usr/local/lib/python/dist-packages, Debian addons install into /usr/{lib,share}/python/dist-packages. /usr/lib/python/site-packages is not used.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top