My company does not (yet) allow us to install or upgrade python3 neither install modules from pip on their servers. Even if I could, the machine is not connected to internet. But we can execute the python2 binary
Use the cx_Oracle
module without using pip
and internet
I got the idea to install cx_Oracle package on my computer and then copy the module files installed from my computer to the server.
So server dev folder looks like this (only listing interesting directories and files, omitting __pychache__
, *.pyc
and other useless *.py
files):
|-- test_cx_oracle_in_local.py
\-- sqlalchemy/
|-- connectors
|-- databases
|-- dialects
| |-- firebird
| |-- mysql
| |-- mssql
| |-- oracle
| | |-- base.py
| | |-- cx_oracle.py <--- This is the interesting file
| | |-- __init__.py
| | \-- zxjdbc.py
| |-- postgresql
| |-- sqlite
| |-- sybase
|-- engine
|-- event
|-- ext
| \-- declarative
|-- orm
|-- pool
|-- sql
|-- testing
| |-- plugin
| \-- suite
\-- util
import cx_Oracle
if __name__ == "__main__":
cx_Oracle.connect(user="xxxxxxxx", password="xxxxxxxx", dns="xxxxxxxx")
Output:
Traceback (most recent call last):
File "test_cx_oracle_in_local.py", line xx, in <module>
import cx_oracle
ImportError: No module named cx_Oracle
from sqlalchemy.dialects.oracle.cx_oracle import cx_Oracle
if __name__ == "__main__":
cx_Oracle.connect(user="xxxxxxxx", password="xxxxxxxx", dns="xxxxxxxx")
Output:
Traceback (most recent call last):
File "test_cx_oracle_in_local.py", line 36, in __init__
self.connection = cx_oracle.connect(user="xxxxxxxx", password="xxxxxxxx", dns="xxxxxxxx")
AttributeError: 'module' object has no attribute 'connect'
Using STACKOVERFLOW - Import a module from a relative path
import os, sys, inspect
sys.path.insert(0, xxxxxxxx) # <--- see link above to see sorin's answer
import cx_oracle
if __name__ == "__main__":
print("SYS_PATH = " + str(sys.path))
cx_Oracle.connect(user="xxxxxxxx", password="xxxxxxxx", dns="xxxxxxxx")
Output:
SYS_PATH = ['/xxxxxxxx/sqlalchemy/dialects/oracle', '/xxxxxxxx/sqlalchemy/dialects', '/xxxxxxxx/sqlalchemy', 'xxxxxxxx', ...]
File "test_cx_oracle_in_local.py", line xx, in <module>
import cx_oracle
File "/xxxxxxxx/sqlalchemy/dialects/oracle/cx_oracle.py", line 286, in <module>
from . import base as oracle
ValueError: Attempted relative import in non-package
UNIX
family (not a Windows/MAC)/bin
, /usr
, /opt
, etc.pip
, pip
is not even installed on the serverpython 2
but I am interested for python 3
solution if you haveHow can I fully use the module cx_Oracle
without internet and without using pip
neither having +wx
access to system folder?
The cx_oracle.py
file in the sqlalchemy
folder is not actually the cx_Oracle library - it's just a sqlalchemy wrapper for the actual cx_Oracle library, which is a compiled binary (including the compiled ODPI-C library, written in C).
Easiest way I can think of:
cx_Oracle.so
somewhere on your server. This is the binary cx_Oracle library file.import cx_Oracle
should work.