- Oracle В® Linux 8
- Installing and Managing Python
- Oracle Legal Notices
- Oracle Documentation License
- Oracle linux install python
- Install Python and Additional Libraries
- Upload the API and the Machine Learning Model
- Install and Configure Gunicorn on Oracle Linux
- Install and Configure Nginx on Oracle Linux
- cx_Oracle 8 Installation¶
- Overview¶
- Quick Start cx_Oracle Installation¶
- Oracle Client and Oracle Database Interoperability¶
- Installing cx_Oracle on Linux¶
- Install cx_Oracle¶
- Install Oracle Client¶
- Oracle Instant Client Zip Files¶
- Oracle Instant Client RPMs¶
- Local Database or Full Oracle Client¶
- Installing cx_Oracle RPMs on Oracle Linux¶
- Installing cx_Oracle on Windows¶
- Install cx_Oracle¶
- Install Oracle Client¶
- Oracle Instant Client Zip Files¶
- Local Database or Full Oracle Client¶
- Installing cx_Oracle on macOS (Intel x86)В¶
- Install Python¶
- Install cx_Oracle¶
- Install Oracle Instant Client¶
- Manual Installation¶
- Scripted Installation¶
- Configure Oracle Instant Client¶
- Linux Containers¶
- Installing cx_Oracle without Internet Access¶
- Install Using GitHub¶
- Install Using Source from PyPI¶
- Upgrading from Older Versions¶
- Installing cx_Oracle in Python 2В¶
- Installing cx_Oracle 5.3В¶
- Troubleshooting¶
Oracle В® Linux 8
Installing and Managing Python
Oracle Legal Notices
Copyright В© 2020, 2021, Oracle and/or its affiliates.
This software and related documentation are provided under a license agreement containing restrictions on use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is prohibited.
The information contained herein is subject to change without notice and is not warranted to be error-free. If you find any errors, please report them to us in writing.
If this is software or related documentation that is delivered to the U.S. Government or anyone licensing it on behalf of the U.S. Government, then the following notice is applicable:
U.S. GOVERNMENT END USERS: Oracle programs (including any operating system, integrated software, any programs embedded, installed or activated on delivered hardware, and modifications of such programs) and Oracle computer documentation or other Oracle data delivered to or accessed by U.S. Government end users are «commercial computer software» or «commercial computer software documentation» pursuant to the applicable Federal Acquisition Regulation and agency-specific supplemental regulations. As such, the use, reproduction, duplication, release, display, disclosure, modification, preparation of derivative works, and/or adaptation of i) Oracle programs (including any operating system, integrated software, any programs embedded, installed or activated on delivered hardware, and modifications of such programs), ii) Oracle computer documentation and/or iii) other Oracle data, is subject to the rights and limitations specified in the license contained in the applicable contract. The terms governing the U.S. Government’s use of Oracle cloud services are defined by the applicable contract for such services. No other rights are granted to the U.S. Government.
This software or hardware is developed for general use in a variety of information management applications. It is not developed or intended for use in any inherently dangerous applications, including applications that may create a risk of personal injury. If you use this software or hardware in dangerous applications, then you shall be responsible to take all appropriate fail-safe, backup, redundancy, and other measures to ensure its safe use. Oracle Corporation and its affiliates disclaim any liability for any damages caused by use of this software or hardware in dangerous applications.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
Intel and Intel Inside are trademarks or registered trademarks of Intel Corporation. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. AMD, Epyc, and the AMD logo are trademarks or registered trademarks of Advanced Micro Devices. UNIX is a registered trademark of The Open Group.
This software or hardware and documentation may provide access to or information about content, products, and services from third parties. Oracle Corporation and its affiliates are not responsible for and expressly disclaim all warranties of any kind with respect to third-party content, products, and services unless otherwise set forth in an applicable agreement between you and Oracle. Oracle Corporation and its affiliates will not be responsible for any loss, costs, or damages incurred due to your access to or use of third-party content, products, or services, except as set forth in an applicable agreement between you and Oracle.
Oracle Documentation License
This document uses the Web-based Help format from DocBook XML. The following license information applies to this format.
Copyright В© 1999-2007 Norman Walsh
Copyright В© 2003 Jiri Kosek
Copyright В© 2004-2007 Steve Ball
Copyright В© 2005-2008 The DocBook Project
Copyright В© 2011-2012 O’Reilly Media
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the «Software»), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
Except as contained in this notice, the names of individuals credited with contribution to this software shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from the individuals in question.
Any stylesheet derived from this Software that is publicly distributed will be identified with a different name and the version strings in any derived Software will be changed so that no possibility of confusion between the derived package and this Software will exist.
THE SOFTWARE IS PROVIDED «AS IS», WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL NORMAN WALSH OR ANY OTHER CONTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Web-based Help from DocBook XML
Copyright В© 2008-2012 Kasun Gajasinghe, David Cramer
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
Except as contained in this notice, the names of individuals credited with contribution to this software shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from the individuals in question.
Any stylesheet derived from this Software that is publicly distributed will be identified with a different name and the version strings in any derived Software will be changed so that no possibility of confusion between the derived package and this Software will exist.
Warranty: THE SOFTWARE IS PROVIDED «AS IS», WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL DAVID CRAMER, KASUN GAJASINGHE, OR ANY OTHER CONTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Certain search characteristics associated with the DocBook XSL webhelp stylesheets are provided as javascript files generated using Apache Lucene and other fourth party technologies, which are licensed under the Apache License reproduced below.
Источник
Oracle linux install python
To set up an Oracle Linux instance on Oracle Cloud Infrastructure, install Python 3.6, Nginx for use as a proxy, and Gunicorn as the web server gateway interface (WSGI) server. Also upload the machine learning model that the API uses.
Other proxies and WSGI servers are available, but both Gunicorn and Nginx provide the performance that’s needed without being over-complicated or resource-heavy.
Install Python and Additional Libraries
The default Python on Oracle Linux 7.6 and 7.7 is 2.7, but you need Python 3. Also install the Flask framework and the dependencies for the machine learning model.
- Log into your Oracle Linux compute instance.
- Install Python 3.6.
If your model relies on other libraries such as tensorflow or pandas, install those too.
Upload the API and the Machine Learning Model
Upload the two API files and the machine learning model to your Oracle Linux instance on Oracle Cloud Infrastructure Compute .
After uploading, run a couple of tests to make sure everything is working.
To upload and test your files:
- Run the following commands in a Bash terminal on your local development system.
Use the private key that corresponds to the public key that you used when provisioning the instance.
The response should be similar to «54%» and may differ depending on how you built your model. Also, the response is displayed before the Bash prompt, as shown in the following snippet:
The response should be similar to «0.54» and may differ depending on how you built your model.
Install and Configure Gunicorn on Oracle Linux
Install and configure the Gunicorn WSGI server to start on system boot. Also configure Gunicorn to communicate with the Nginx proxy via a UNIX socket which is more efficient and secure than using a TCP/IP socket (ie, http://127.0.0.1).
To install and configure Gunicorn:
- Log into your compute instance and activate the apienv environment.
The mlapi.sock file that’s specified in the ExecStart line is created in the WorkingDirectory by Gunicorn when it starts up the first time. This is the file that Gunicorn and Nginx use to communicate with each other instead of through a TCP socket.
Install and Configure Nginx on Oracle Linux
The built-in server that Flask provides is not suited for production use. To safely expose your API to the network, you should use a Python WSGI server such as Gunicorn behind a proxy such as Nginx.
- Log into your compute instance.
- Install Nginx from the yum repository.
Connect your Skill Bot to a Machine Learning API
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
This software and related documentation are provided under a license agreement containing restrictions on use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is prohibited.
The information contained herein is subject to change without notice and is not warranted to be error-free. If you find any errors, please report them to us in writing.
If this is software or related documentation that is delivered to the U.S. Government or anyone licensing it on behalf of the U.S. Government, then the following notice is applicable:
U.S. GOVERNMENT END USERS: Oracle programs, including any operating system, integrated software, any programs installed on the hardware, and/or documentation, delivered to U.S. Government end users are «commercial computer software» pursuant to the applicable Federal Acquisition Regulation and agency-specific supplemental regulations. As such, use, duplication, disclosure, modification, and adaptation of the programs, including any operating system, integrated software, any programs installed on the hardware, and/or documentation, shall be subject to license terms and license restrictions applicable to the programs. No other rights are granted to the U.S. Government.
This software or hardware is developed for general use in a variety of information management applications. It is not developed or intended for use in any inherently dangerous applications, including applications that may create a risk of personal injury. If you use this software or hardware in dangerous applications, then you shall be responsible to take all appropriate fail-safe, backup, redundancy, and other measures to ensure its safe use. Oracle Corporation and its affiliates disclaim any liability for any damages caused by use of this software or hardware in dangerous applications.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
Intel and Intel Xeon are trademarks or registered trademarks of Intel Corporation. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. AMD, Opteron, the AMD logo, and the AMD Opteron logo are trademarks or registered trademarks of Advanced Micro Devices. UNIX is a registered trademark of The Open Group.
This software or hardware and documentation may provide access to or information about content, products, and services from third parties. Oracle Corporation and its affiliates are not responsible for and expressly disclaim all warranties of any kind with respect to third-party content, products, and services unless otherwise set forth in an applicable agreement between you and Oracle. Oracle Corporation and its affiliates will not be responsible for any loss, costs, or damages incurred due to your access to or use of third-party content, products, or services, except as set forth in an applicable agreement between you and Oracle.
Источник
cx_Oracle 8 Installation¶
Overview¶
To use cx_Oracle 8 with Python and Oracle Database you need:
- Python 3.5 and higher. Older versions of cx_Oracle may work with older versions of Python.
- Oracle Client libraries. These can be from the free Oracle Instant Client, from a full Oracle Client installation, or from those included in Oracle Database if Python is on the same machine as the database. Oracle client libraries versions 21, 19, 18, 12, and 11.2 are supported where available on Linux, Windows and macOS (Intel x86). Users have also reported success with other platforms. Use the latest client possible: Oracle’s standard client-server version interoperability allows connection to both older and newer databases.
- An Oracle Database, either local or remote.
The cx_Oracle module loads Oracle Client libraries which communicate over Oracle Net to an existing database. Oracle Net is not a separate product: it is how the Oracle Client and Oracle Database communicate.
Fig. 2 cx_Oracle Architecture
Quick Start cx_Oracle Installation¶
Alternatively you can:
Install Python 3, if not already available. On macOS you must always install your own Python.
Python 3.5 and higher are supported by cx_Oracle 8. If you use Python 2, then the older cx_Oracle 7.3 will install.
Install cx_Oracle from PyPI with:
Note: if a binary wheel package is not available for your platform, the source package will be downloaded instead. This will be compiled and the resulting binary installed.
The —user option may be useful, if you don’t have permission to write to system directories:
If you are behind a proxy, add a proxy server to the command, for example add —proxy=http://proxy.example.com:80
Add Oracle 21, 19, 18, 12 or 11.2 client libraries to your operating system library search path such as PATH on Windows or LD_LIBRARY_PATH on Linux. On macOS use init_oracle_client() in your application to pass the Oracle Client directory name, see Using cx_Oracle.init_oracle_client() to set the Oracle Client directory . This is also usable on Windows.
To get the libraries:
If your database is on a remote computer, then download and unzip the client libraries from the free Oracle Instant Client “Basic” or “Basic Light” package for your operating system architecture.
Instant Client on Windows requires an appropriate Microsoft Windows Redistributables, see Installing cx_Oracle on Windows . On Linux, the libaio (sometimes called libaio1 ) package is needed. Oracle Linux 8 also needs the libnsl package.
Alternatively, use the client libraries already available in a locally installed database such as the free Oracle Database Express Edition (“XE”) release.
Version 21 client libraries can connect to Oracle Database 12.1 or greater. Version 19, 18 and 12.2 client libraries can connect to Oracle Database 11.2 or greater. Version 12.1 client libraries can connect to Oracle Database 10.2 or greater. Version 11.2 client libraries can connect to Oracle Database 9.2 or greater.
Create a script like the one below:
Locate your Oracle Database username and password, and the database connection string. The connection string is commonly of the format hostname/servicename , using the hostname where the database is running, and using the service name of the Oracle Database instance.
Substitute your username, password and connection string in the code. Run the Python script, for example:
You can learn how to use cx_Oracle from the API documentation and samples.
If you run into installation trouble, check out the section on Troubleshooting.
Oracle Client and Oracle Database Interoperability¶
cx_Oracle requires Oracle Client libraries. The libraries provide the necessary network connectivity to access an Oracle Database instance. They also provide basic and advanced connection management and data features to cx_Oracle.
The simplest way to get Oracle Client libraries is to install the free Oracle Instant Client “Basic” or “Basic Light” package. The libraries are also available in any Oracle Database installation or full Oracle Client installation.
Oracle’s standard client-server network interoperability allows connections between different versions of Oracle Client libraries and Oracle Database. For certified configurations see Oracle Support’s Doc ID 207303.1. In summary, Oracle Client 21 can connect to Oracle Database 12.1 or greater. Oracle Client 19, 18 and 12.2 can connect to Oracle Database 11.2 or greater. Oracle Client 12.1 can connect to Oracle Database 10.2 or greater. Oracle Client 11.2 can connect to Oracle Database 9.2 or greater. The technical restrictions on creating connections may be more flexible. For example Oracle Client 12.2 can successfully connect to Oracle Database 10.2.
cx_Oracle uses the shared library loading mechanism available on each supported platform to load the Oracle Client libraries at runtime. It does not need to be rebuilt for different versions of the libraries. Since a single cx_Oracle binary can use different client versions and also access multiple database versions, it is important your application is tested in your intended release environments. Newer Oracle clients support new features, such as the oraaccess.xml external configuration file available with 12.1 or later clients, session pool improvements, improved high availability features, call timeouts, and other enhancements.
The cx_Oracle function clientversion() can be used to determine which Oracle Client version is in use. The attribute Connection.version can be used to determine which Oracle Database version a connection is accessing. These can then be used to adjust application behavior accordingly. Attempts to use Oracle features that are not supported by a particular client/server library combination will result in runtime errors.
Installing cx_Oracle on Linux¶
This section discusses the generic installation methods on Linux. To use Python and cx_Oracle RPM packages from yum on Oracle Linux, see Installing cx_Oracle RPMs on Oracle Linux .
Install cx_Oracle¶
The generic way to install cx_Oracle on Linux is to use Python’s Pip package to install cx_Oracle from PyPI:
The —user option may be useful, if you don’t have permission to write to system directories:
If you are behind a proxy, add a proxy server to the command, for example add —proxy=http://proxy.example.com:80
This will download and install a pre-compiled binary if one is available for your architecture. If a pre-compiled binary is not available, the source will be downloaded, compiled, and the resulting binary installed. Compiling cx_Oracle requires the Python.h header file. If you are using the default python package, this file is in the python-devel package or equivalent.
Install Oracle Client¶
Using cx_Oracle requires Oracle Client libraries to be installed. These provide the necessary network connectivity allowing cx_Oracle to access an Oracle Database instance.
- If your database is on a remote computer, then download the free Oracle Instant Client “Basic” or “Basic Light” package for your operating system architecture. Use the RPM or ZIP packages, based on your preferences.
- Alternatively, use the client libraries already available in a locally installed database such as the free Oracle Database Express Edition (“XE”) release.
Oracle Instant Client Zip Files¶
To use cx_Oracle with Oracle Instant Client zip files:
Download an Oracle 21, 19, 18, 12, or 11.2 “Basic” or “Basic Light” zip file matching your Python 64-bit or 32-bit architecture:
The latest version is recommended. Oracle Instant Client 21 will connect to Oracle Database 12.1 or later.
Unzip the package into a single directory that is accessible to your application. For example:
Install the libaio package with sudo or as the root user. For example:
On some Linux distributions this package is called libaio1 instead.
On recent Linux versions such as Oracle Linux 8, you may also need to install the libnsl package when using Oracle Instant Client 19.
If there is no other Oracle software on the machine that will be impacted, permanently add Instant Client to the runtime link path. For example, with sudo or as the root user:
Alternatively, set the environment variable LD_LIBRARY_PATH to the appropriate directory for the Instant Client version. For example:
If you use optional Oracle configuration files such as tnsnames.ora , sqlnet.ora or oraaccess.xml with Instant Client, then put the files in an accessible directory, for example in /opt/oracle/your_config_dir . Then use:
Or set the environment variable TNS_ADMIN to that directory name.
Alternatively, put the files in the network/admin subdirectory of Instant Client, for example in /opt/oracle/instantclient_21_1/network/admin . This is the default Oracle configuration directory for executables linked with this Instant Client.
Oracle Instant Client RPMs¶
To use cx_Oracle with Oracle Instant Client RPMs:
Download an Oracle 21,19, 18, 12, or 11.2 “Basic” or “Basic Light” RPM matching your Python architecture:
Oracle’s yum server has convenient repositories:
The latest version is recommended. Oracle Instant Client 21 will connect to Oracle Database 12.1 or later.
Install the downloaded RPM with sudo or as the root user. For example:
Yum will automatically install required dependencies, such as libaio .
On recent Linux versions, such as Oracle Linux 8, you may need to manually install the libnsl package when using Oracle Instant Client 19.
For Instant Client 19, or later, the system library search path is automatically configured during installation.
For older versions, if there is no other Oracle software on the machine that will be impacted, permanently add Instant Client to the runtime link path. For example, with sudo or as the root user:
Alternatively, for version 18 and earlier, every shell running Python will need to have the environment variable LD_LIBRARY_PATH set to the appropriate directory for the Instant Client version. For example:
If you use optional Oracle configuration files such as tnsnames.ora , sqlnet.ora or oraaccess.xml with Instant Client, then put the files in an accessible directory, for example in /opt/oracle/your_config_dir . Then use:
Or set the environment variable TNS_ADMIN to that directory name.
Alternatively, put the files in the network/admin subdirectory of Instant Client, for example in /usr/lib/oracle/21/client64/lib/network/admin . This is the default Oracle configuration directory for executables linked with this Instant Client.
Local Database or Full Oracle Client¶
cx_Oracle applications can use Oracle Client 21, 19, 18, 12, or 11.2 libraries from a local Oracle Database or full Oracle Client installation.
The libraries must be either 32-bit or 64-bit, matching your Python architecture.
Set required Oracle environment variables by running the Oracle environment script. For example:
For Oracle Database Express Edition (“XE”) 11.2, run:
Optional Oracle configuration files such as tnsnames.ora , sqlnet.ora or oraaccess.xml can be placed in $ORACLE_HOME/network/admin .
Alternatively, Oracle configuration files can be put in another, accessible directory. Then set the environment variable TNS_ADMIN to that directory name.
Installing cx_Oracle RPMs on Oracle Linux¶
Python and cx_Oracle RPM packages are available from the Oracle Linux yum server. Various versions of Python are easily installed. Using the yum server makes it easy to keep up to date.
Installing cx_Oracle on Windows¶
Install cx_Oracle¶
Use Python’s Pip package to install cx_Oracle from PyPI:
If you are behind a proxy, specify your proxy server:
This will download and install a pre-compiled binary if one is available for your architecture. If a pre-compiled binary is not available, the source will be downloaded, compiled, and the resulting binary installed.
Install Oracle Client¶
Using cx_Oracle requires Oracle Client libraries to be installed. These provide the necessary network connectivity allowing cx_Oracle to access an Oracle Database instance. Oracle Client versions 19, 18, 12 and 11.2 are supported.
- If your database is on a remote computer, then download the free Oracle Instant Client “Basic” or “Basic Light” package for your operating system architecture.
- Alternatively, use the client libraries already available in a locally installed database such as the free Oracle Database Express Edition (“XE”) release.
Oracle Instant Client Zip Files¶
To use cx_Oracle with Oracle Instant Client zip files:
Download an Oracle 19, 18, 12, or 11.2 “Basic” or “Basic Light” zip file: 64-bit or 32-bit, matching your Python architecture.
The latest version is recommended. Oracle Instant Client 19 will connect to Oracle Database 11.2 or later.
Windows 7 users: Note that Oracle 19c is not supported on Windows 7.
Unzip the package into a directory that is accessible to your application. For example unzip instantclient-basic-windows.x64-19.11.0.0.0dbru.zip to C:\oracle\instantclient_19_11 .
Oracle Instant Client libraries require a Visual Studio redistributable with a 64-bit or 32-bit architecture to match Instant Client’s architecture. Each Instant Client version requires a different redistributable version:
- For Instant Client 19 install VS 2017.
- For Instant Client 18 or 12.2 install VS 2013
- For Instant Client 12.1 install VS 2010
- For Instant Client 11.2 install VS 2005 64-bit or VS 2005 32-bit
Configure Oracle Instant Client¶
There are several alternative ways to tell cx_Oracle where your Oracle Client libraries are, see cx_Oracle 8 Initialization .
With Oracle Instant Client you can use init_oracle_client() in your application, for example:
Note a вЂraw’ string is used because backslashes occur in the path.
Alternatively, add the Oracle Instant Client directory to the PATH environment variable. The directory must occur in PATH before any other Oracle directories. Restart any open command prompt windows.
Another way to set PATH is to use a batch file that sets it before Python is executed, for example:
Invoke this batch file every time you want to run Python.
If you use optional Oracle configuration files such as tnsnames.ora , sqlnet.ora or oraaccess.xml with Instant Client, then put the files in an accessible directory, for example in C:\oracle\your_config_dir . Then use:
Or set the environment variable TNS_ADMIN to that directory name.
Alternatively, put the files in a network\admin subdirectory of Instant Client, for example in C:\oracle\instantclient_19_11\network\admin . This is the default Oracle configuration directory for executables linked with this Instant Client.
Local Database or Full Oracle Client¶
cx_Oracle applications can use Oracle Client 19, 18, 12, or 11.2 libraries libraries from a local Oracle Database or full Oracle Client.
The Oracle libraries must be either 32-bit or 64-bit, matching your Python architecture.
Set the environment variable PATH to include the path that contains OCI.DLL , if it is not already set.
Restart any open command prompt windows.
Optional Oracle configuration files such as tnsnames.ora , sqlnet.ora or oraaccess.xml can be placed in the network\admin subdirectory of the Oracle Database software installation.
Alternatively, pass config_dir to init_oracle_client() as shown in the previous section, or set TNS_ADMIN to the directory name.
Installing cx_Oracle on macOS (Intel x86)В¶
Install Python¶
Make sure you are not using the bundled Python. This has restricted entitlements and will fail to load Oracle client libraries. Instead use Homebrew or Python.org.
A C compiler is needed, for example Xcode and its command line tools.
Install cx_Oracle¶
Use Python’s Pip package to install cx_Oracle from PyPI:
The —user option may be useful, if you don’t have permission to write to system directories:
If you are behind a proxy, add a proxy server to the command, for example add —proxy=http://proxy.example.com:80
The source will be downloaded, compiled, and the resulting binary installed.
Install Oracle Instant Client¶
Oracle Instant Client provides the network connectivity for accessing Oracle Database.
Manual Installation¶
Download the Basic 64-bit DMG from Oracle.
In Finder, double click on the DMG to mount it.
Open a terminal window and run the install script in the mounted package, for example:
This copies the contents to $HOME/Downloads/instantclient_19_8 . Applications may not have access to the Downloads directory, so you should move Instant Client somewhere convenient.
In Finder, eject the mounted Instant Client package.
If you have multiple Instant Client DMG packages mounted, you only need to run install_ic.sh once. It will copy all mounted Instant Client DMG packages at the same time.
Scripted Installation¶
Instant Client installation can alternatively be scripted, for example:
The Instant Client directory will be $HOME/Downloads/instantclient_19_8 . Applications may not have access to the Downloads directory, so you should move Instant Client somewhere convenient.
Configure Oracle Instant Client¶
Call init_oracle_client() once in your application:
If you use optional Oracle configuration files such as tnsnames.ora , sqlnet.ora or oraaccess.xml with Oracle Instant Client, then put the files in an accessible directory, for example in /Users/your_username/oracle/your_config_dir . Then use:
Or set the environment variable TNS_ADMIN to that directory name.
Alternatively, put the files in the network/admin subdirectory of Oracle Instant Client, for example in /Users/your_username/Downloads/instantclient_19_8/network/admin . This is the default Oracle configuration directory for executables linked with this Instant Client.
Linux Containers¶
Sample Dockerfiles are on GitHub.
Pre-built images for Python and cx_Oracle are in the GitHub Container Registry. These are easily used. For example, to pull an Oracle Linux 8 image with Python 3.6 and cx_Oracle, execute:
Installing cx_Oracle without Internet Access¶
To install cx_Oracle on a computer that is not connected to the internet, download the appropriate cx_Oracle file from PyPI. Transfer this file to the offline computer and install it with:
Then follow the general cx_Oracle platform installation instructions to install Oracle client libraries.
Install Using GitHub¶
In order to install using the source on GitHub, use the following commands:
Note that if you download a source zip file directly from GitHub then you will also need to download an ODPI-C source zip file and extract it inside the directory called “odpi”.
cx_Oracle source code is also available from opensource.oracle.com. This can be cloned with:
Install Using Source from PyPI¶
The source package can be downloaded manually from PyPI and extracted, after which the following commands should be run:
Upgrading from Older Versions¶
Review the release notes and Deprecations for changes. Modify affected code.
If you are upgrading from cx_Oracle 7 note these changes:
- The default character set used by cx_Oracle 8 is now “UTF-8”. Also, the character set component of the NLS_LANG environment variable is ignored. If you need to change the character set, then pass encoding and nendcoding parameters when creating a connection or connection pool. See Character Sets and Globalization .
- Any uses of type(var) need to be changed to var.type .
- Any uses of var.type is not None need to be changed to isinstance(var.type, cx_Oracle.ObjectType)
- Note that TIMESTAMP WITH TIME ZONE columns will now be reported as cx_Oracle.DB_TYPE_TIMESTAMP_TZ instead of cx_Oracle.TIMESTAMP in Cursor.description .
- Note that TIMESTAMP WITH LOCAL TIME ZONE columns will now be reported as cx_Oracle.DB_TYPE_TIMESTAMP_LTZ instead of cx_Oracle.TIMESTAMP in Cursor.description .
- Note that BINARY_FLOAT columns will now be reported as cx_Oracle.DB_TYPE_BINARY_FLOAT instead of cx_Oracle.NATIVE_DOUBLE in Cursor.description .
If you are upgrading from cx_Oracle 5 note these installation changes:
- When using Oracle Instant Client, you should not set ORACLE_HOME .
- On Linux, cx_Oracle 6 and higher no longer uses Instant Client RPMs automatically. You must set LD_LIBRARY_PATH or use ldconfig to locate the Oracle client library.
- PyPI no longer allows Windows installers or Linux RPMs to be hosted. Use the supplied cx_Oracle Wheels instead, or use RPMs from Oracle, see Installing cx_Oracle RPMs on Oracle Linux .
Installing cx_Oracle in Python 2В¶
cx_Oracle 7.3 was the last version with support for Python 2.
If you install cx_Oracle in Python 2 using the commands provided above, then cx_Oracle 7.3 will be installed. This is equivalent to using a command like:
For other installation options such as installing through a proxy, see instructions above. Make sure the Oracle Client libraries are in the system library search path because cx_Oracle 7 does not support the cx_Oracle.init_oracle_client() method and does not support loading the Oracle Client libraries from the directory containing the cx_Oracle module binary.
Installing cx_Oracle 5.3В¶
If you require cx_Oracle 5.3, download a Windows installer from PyPI or use python -m pip install cx-oracle==5.3 to install from source.
Very old versions of cx_Oracle can be found in the files section at SourceForce.
Troubleshooting¶
If installation fails:
- Use option -v with pip. Review your output and logs. Try to install using a different method. Google anything that looks like an error. Try some potential solutions.
- Was there a network connection error? Do you need to set the environment variables http_proxy and/or https_proxy ? Or try pip install —proxy=http://proxy.example.com:80 cx_Oracle —upgrade ?
- If upgrading gave no errors but the old version is still installed, try pip install cx_Oracle —upgrade —force-reinstall
- If you do not have access to modify your system version of Python, can you use pip install cx_Oracle —upgrade —user or venv?
- Do you get the error “ No module named pip ”? The pip module is builtin to Python but is sometimes removed by the OS. Use the venv module (builtin to Python 3.x) or virtualenv module instead.
- Do you get the error “ fatal error: dpi.h: No such file or directory ” when building from source code? Ensure that your source installation has a subdirectory called “odpi” containing files. If missing, review the section on Install Using GitHub.
If using cx_Oracle fails:
Do you get the error “ DPI-1047: Oracle Client library cannot be loaded ”?
Check that Python and your Oracle Client libraries are both 64-bit, or both 32-bit. The DPI-1047 message will tell you whether the 64-bit or 32-bit Oracle Client is needed for your Python.
Set the environment variable DPI_DEBUG_LEVEL to 64 and restart cx_Oracle. The trace messages will show how and where cx_Oracle is looking for the Oracle Client libraries.
At a Windows command prompt, this could be done with:
On Linux and macOS, you might use:
On Windows, if you used init_oracle_client() and have a full database installation, make sure this database is the currently configured database.
On Windows, if you are not using init_oracle_client() , then restart your command prompt and use set PATH to check the environment variable has the correct Oracle Client listed before any other Oracle directories.
On Windows, use the DIR command to verify that OCI.DLL exists in the directory passed to init_oracle_client() or set in PATH .
On Windows, check that the correct Windows Redistributables have been installed.
On Linux, check the LD_LIBRARY_PATH environment variable contains the Oracle Client library directory. If you are using Oracle Instant Client, a preferred alternative is to ensure a file in the /etc/ld.so.conf.d directory contains the path to the Instant Client directory, and then run ldconfig .
On macOS, make sure you are not using the bundled Python (use Homebrew or Python.org instead). If you are not using init_oracle_client() , then put the Oracle Instant Client libraries in
/lib or /usr/local/lib .
If you got “ DPI-1072: the Oracle Client library version is unsupported ”, then review the installation requirements. cx_Oracle needs Oracle client libraries 11.2 or later. Note that version 19 is not supported on Windows 7. Similar steps shown above for DPI-1047 may help.
If you have multiple versions of Python installed, make sure you are using the correct python and pip (or python3 and pip3) executables.
© Copyright 2016, 2020, Oracle and/or its affiliates. All rights reserved. Portions Copyright В© 2007-2015, Anthony Tuininga. All rights reserved. Portions Copyright В© 2001-2007, Computronix (Canada) Ltd., Edmonton, Alberta, Canada. All rights reserved Revision 08117db4 .
Источник