No root privileges under Debian to access Oracle using Python

Source: Internet
Author: User
Tags virtual environment virtualenv

The reason for this article is that there is no root permission on the company's servers, but you need to use Python to access Oracle, regardless of whether you use PIP to install components or to install Oracle's client. This article resolves the issue.

Use virtualenv

When you use the system to bring Python and pip install components, it is installed to the system directory by default and requires root privileges to perform write operations.

You need a handy Python virtual environment tool from the standpoint of resource isolation or bypassing root: virtualenv .

Go to find Ops brother to help install virtualenv it. By the way, pip and virtualenv under Debian can be directly used to apt-get install, the corresponding package is python-pip and virtualevn . If not on the server, boldly provide a single bar.

About virtualenv , this article no longer repeat, if in doubt, please step my another article "Talk about virtualenv and Virtualenvwrapper practice".

With this virtualenv , you can create your own Python virtual environment, which does not require any root privileges in the virtual environment. Then the work is done in the virtual.

Installation cx_Oracle

Access to Oracle in Python cx_Oracle is required, and installation can be used directly here pip .

pip install cx_Oracle --pre

I came across an installation process prompted not to find the Python.h file, which indicates that the system python-dev is missing packages, is used apt-get , the same please do the operation of the maintenance of the line.

Installing Instantclient

Just install the cx_oracle, the import will be reported when the library is not found. and install Oracle's official instantclient. Here, Instant Client Package - Basic you can download it.

After downloading, enter a directory that has permissions, if it is the root directory of the user ~ . Unzip the downloaded Zip package, for example to the ~/oracle/instantclient_12_2/ directory. After that, you need to add environment variables to enable the system to find these libraries. In the terminal's RC file, such as the ~/.bashrc end, add the environment variable as follows.

export ORACLE_HOME=$HOME/oracle/instantclient_12_2export LD_LIBRATY_PATH=$ORACLE_HOME:$LD_LIBRATY_PATHexport PATH=$ORACLE_HOME:$PATH

At this point, one more thing to do is to create libclntsh.so a soft link.

ln -s libclntsh.so.12.1 libclntsh.so

The reason for doing this is that cx_Oracle you need to use the library file libclntsh.so , but instantclient only the library file with the version number after the decompression, so we need to manually make a soft link for identification.

Next, let the RC file that you just modified the environment variable take effect.

source ~/.bashrc

It is important to note that after this time source , the virtual environment that was previously entered will be exited. If you still need to continue the eight-ring theater in a virtual environment, you need to enter it again .

End

Now, theoretically it should be possible to www.rcsx.org normal in Python import cx_Oracle . If possible, instructions and can be used.

If not, you need to add some of the packages mentioned in the error. I found a missing libaio1 and two package in the system during the test libaio-dev . Please take the OPS together.

Enjoy Your work ~

No root privileges under Debian to access Oracle using Python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.