I recently installed cx_Oracle module on my machine, in order to connect to a remote Oracle database server. (I have no Oracle client at my side).
Python: Version 2.7 x86
Oracle: Verision 11.1.X x64
Cx_Oracle:Verion-5.1.2-11g.win32-py2.7
Then everytime I run my script, it fails and print the following message:
ImportError: DLL load failed: The specified module could not be found.
I found a related post at Here, so I am wondering if I anyway have to have an Oracle client at my side where the python script is invoked.
Can anyone help me out? Thanks in advance.
# - This import requires appropriate oraocciXX.dll to be available in PATH (on windows)
# (Probably LD_LIBRARY_PATH or LD_LIBRARY_PATH64 on POSIX)
# where XX is the oracle DB version, e.g. oraocci11.dll for Oracle 11g.
# - This dll is part of the Oracle Instant client pkg available here:
# http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
# - Also ensure that python, cx_Oracle and Oracle Client are of same arch (32 or 64-bit)
#
import cx_Oracle
You can find out arch (32 or 64-bit) for:
python by just running the python in interactive mode on command line.
cx_Oracle: look at the name of downloaded file.
Oracle Client:
run the sqlplus that's part of your client package
start Task Manager and see if sqlplus.exe has "*32" next to it (=32 bit) or not (=64 bit)
if you don't have sqlplus, use dumpbin /headers oraocciXX.dll
If you're using POSIX you probably would already know. Use file oraocciXX.so
Finally if you still don't understand here is really for dummies instructions:
Ensure you've installed 32-bit versions of python, cx_Oracle and Oracle Instant Client. These could also be 64-bit, but must be same for all 3. Can not mix and match. Links:
Oracle Instant Client Lets say it's installed in C:\ProgFiles\OraClient\11_2
cx_Oracle
Python
Windows:
set PATH=%PATH%;C:\ProgFiles\OraClient\11_2
POSIX (Linux/Unix/Solaris...) <-- Untested..
export LD_LIBRARY_PATH=/path/to/your/32bit/oraocciXX.so
(64 bit) export LD_LIBRARY_PATH64=/path/to/your/64bit/oraocciXX.so
run path-to-python/python.exe -c "import cx_Oracle" to test whether your setup is working or not.
if it prints
nothing: then it's successful.
ImportError: DLL load failed: The specified module could not be found: then oraocciXX is not found. Setup the env vars correctly.
ImportError: DLL load failed: %1 is not a valid Win32 application: You have a 32/64 bit mismatch.
Yes, you have to have an Oracle client installed at your side.
From the cx_ORacle README
"Please note that an Oracle client (or server) installation is required in order
to use cx_Oracle. If you do not require the tools that come with a full client
installation, it is recommended to install the Instant Client which is far
easier to install."
EDIT link to Instant Client: http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
After having been trying to solve this issue for days, I found out that set PATH=%PATH%:<insert Oracle home here> did not do the trick for me. I had to go into my Windows XP system properties and append the Oracle home to the 'path' variable under 'System variables'.
I cannot comment yet :-( but for uniquephase above, you may want to try to check the permissions of the .exe and .dlls to make sure they are executable?
So the steps I needed to do to get it working.
Unzip the instant client from here.
http://www.oracle.com/technetwork/topics/winx64soft-089540.html
chmod +x *.exe *.dll (I am using cygwin).
For completeness, I couldnt get cx_oracle to install via pip using cygwin.
So I had to use standard dist python (non-cygwin) and installed cx_oracle via the windows installer.
Also, I had to add f:/opt/instantclient_12_1 (location where I installed the Oracle instant client) to the Windows path (via System->Advanced System Properties->Environment Variables->System Variables).
Related
I am quite puzzled by the following situation: a colleague and I both use Mac OS X. I use 10.15.3, python 2.7.15, GCC 4.2.1, cx_Oracle 7.0.0 with the SQL Developer 19.1.0. She uses 10.14.6, python 2.7.10, GCC 4.2.1, cx_Oracle 7.3.0 with the SQL Developer 18.3.0.
We have a simple python script that connects to a data base via cx_Oracle. We got the usual DPI-1047 error. I followed the instructions here https://oracle.github.io/odpi/doc/installation.html#macos and with the latest 19 "Basic" version, and a bit of tweaking because of the notarization (https://github.com/oracle/python-cx_Oracle/issues/341#issuecomment-541794557) I could make it work: the .dylib files are properly picked up and the code can connect to the db.
For my colleague, the file cannot be found. We followed the exact same steps as for my computer, downloaded first the 19 then the 18 "Basic" version (naively thinking it would be related to the SQL Developer version), unzipped, and added the link to the $LD_LIBRARY_PATH variable. However, the DPI-1047 error remains to pop up.
We tried to follow previous solutions in this or other forums, but they wouldn't apply or work for us:
https://github.com/oracle/python-cx_Oracle/issues/210 (with https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html#ic_x64_inst) -> the same for us except the "per step 3" part does not apply -> we do not have any .so files in the instantclient download
DPI-1047: 64-bit Oracle Client library cannot be loaded - we verified that we both use 64-bit python using python -c 'import sys;print("%x" % sys.maxsize, sys.maxsize > 2**32)', rest in this thread applies to Windows
How to fix: cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library - Python - there is no /usr/lib/oracle folder, neither for me nor for her, where one would need to set the version explicitly; in fact, the downloaded folder contains a soft link to the proper version of the .dylib already (we also played around with having it point to other .dylib versions)
Thank you for your help!
c.
In summary you have an issue on the 10.14.6 (Mojave) computer.
My initial thought was that you are using the OS default Python. This won't work because Apple has locked it down. From the install instructions: "Make sure you are not using the bundled Python. This has restricted entitlements and will fail to load Oracle client libraries." (I have not/cannot venture into hacking Instant Client to see if it can be made to work)
However, where did Python 2.7.10 come from? My system default is Python 2.7.16.
Don't set LD_LIBRARY_PATH. Instead my ~/lib directory has just one symbolic link:
libclntsh.dylib -> /Users/cjones/instantclient_19_3/libclntsh.dylib
All the configuration issues are due to Apple's ever tightening security requirements. Hopefully the next Oracle Instant Client release will make it easier to use.
SQL Developer is almost completely unrelated to Python cx_Oracle usage (unless you use thick-JDBC connections in SQL Developer, which is rare).
And don't follow Linux or Windows instructions on macOS!
I've been working on FHIR for a project and we are using PostgreSQL as a database. While reading docs, I've come to know about PL/Python and decided to give it a shot but I am unable to install the python extension.
When I run the command CREATE EXTENSION pypthon3u; I get the following error
Could not load library "C:/Program Files/PostgreSQL/12/lib/plpython3.dll": The specified module could not be found.
I've checked this SO answer but it couldn't help.
My PostgreSQL version: PostgreSQL 12.2, compiled by Visual C++ build 1914, 64-bit
Installed Python version: 3.7.7 (64 Bit)
OS Info: Windows 10 Enterprise Version 1909 OS Build 18363.657
For me, it looks like incorrect version of Python but I'm installing python 3.7.* version against which PostgreSQL is compiled as specified in doc\installation-notes.html inside the install directory.
Any help will be appreciated.
Even if you use the EDB installer's Stack Builder to install Python, you still have to follow the instructions to "ensure they are included in the PATH variable under which the database server will be started". I had to do this at the system level, as I can't find a way to set the PATH for individual services.
And then you also need to set PYTHONPATH as well, which seems to be undocumented.
So I ended up adding c:\edb\languagepack\v1\Python-3.7 to PATH and creating PYTHONPATH with c:\edb\languagepack\v1\Python-3.7\Lib.
I had to add directory containing plpython3.dll do system/user variables (windows).
I was trying the same. Though I am no expert and my errors were a bit different, here are a few things to check:
under share\extension\, there should be plpython3u.control and plpython3u--1.0.sql to be able to do CREATE EXTENSION plpython3u;
ensure you are not having any typo in the command above.
under lib\, there should be a plpython3.dll. This one is possibly created after the above step.
make sure lib\ is in your PATH.
PYTHONHOME should be set in either system/user environment, or should be set before the server start. It seems the version is not as much important as having this name set. plpython3.dll seems to look for a python39.dll but I could use it with a 3.8 installation.
I used a zipped version of Postgres, so the following is my way to run the server.
set PATH=%PATH%;d:\pgsql\bin\;d:\pgsql\lib\
set PYTHONHOME=c:\DevTools\Python\Python38
pg_ctl -D d:\pgsql\pgdata -l logfile start
PS: without PYTHONHOME, the server crashes. the server itself or psql restarts the server but I am not sure about pgAdmin.
After trying to connect to DB with cx_Oracle.connect(...) I get the following exception: cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 32-bit Oracle Client Library: "...path" is not the correct architecture.
I am also given a link where there are some info about the libraries and about the fact that Oracle Client libraries "require the presence of the correct Visual Studio redistributable".
The thing is that the only thing I have (where I actually create the DB itself) is Oracle SqlDeveloper.
So.. do I really need to install smth to get it to work?
Your python is 32bit & looking for 32bit cx_Oracle.
You need to install Visual Studio & cx_Oracle.
Refer to this site and download the 32 bit cx_oracle .zip & the VS .exe.
Install the VS .exe (double click to install).
Unzip the cx_oracle zip, put it into your python installation folder, eg.
C:\Python\Python37-32\Lib\site-packages\
to get to this directory
C:\Python\Python37-32\Lib\site-packages\instantclient_19_3\
Set your computer/machine PATH in "environment variable" to include
C:\Python\Python37-32\Lib\site-packages\instantclient_19_3
Restart your machine.
Using Windows 2008 R2 Server. Server was completely clean. Installed 64-bit Python 3.5, 64-bit Oracle Instant Client 12c. pip installed cx_Oracle successfully. When I try to run a python script that imports cx_Oracle however, I get:
ImportError: DLL load failed: The specified module could not be found.
The instant client path is in the PATH environmental variable. I also made another system variable called ORACLE_HOME with the same instant client path.
I've double checked everything is 64-bit, and looked through SO at the many other times this has come up, and no answer has helped.
First, the environment variable ORACLE_HOME should not be set when an instant client is used. Setting it can have unintended side effects!
Second, if you used pip to install cx_Oracle that suggests you have a compiler and it succeeded in compiling the module. Check to make sure that it used the correct libraries.
Third, you can also download and install a pre-built binary from the PyPI site and see if that helps matters any. Make sure you pick the Python 3.5, 64-bit, Oracle 12c version that is listed there. The PyPI site link is here:
https://pypi.python.org/pypi/cx_Oracle
Here's what I did:
I'm on Windows XP SP3
I already had Python 2.7.1 installed.
I downloaded instantclient-basic-nt-11.2.0.3.0.zip, unzipped it, and put it in C:\Program Files\Oracle\instantclient_11_2.
I added this path to the Windows Path environment variable.
I created a new environment variable ORACLE_HOME holding this path as its value.
I installed cx_Oracle-5.1.2-11g.win32-py2.7.msi.
And on running import cx_Oracle all I get is
Traceback (most recent call last):
File "<string>", line 2, in <module>
ImportError: DLL load failed: This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.
I obviously uninstalled / reinstalled cx_Oracle a couple of times but really nothing seems to help. Could anyone please provide a clue how to fix this?
UPDATE
I ran Dependency Walker and it comes up with a lot of trouble. However, the first missing .dll (msvcr80.dll) is actually present in C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.91_x-ww_0de56c07.
OK, what finally solved the problem (not sure whether all steps are necessary and no idea why exactly this and only this worked so far):
Download and unzip version 12 from here.
Add "ORACLE_HOME" as a Windows environment variable and set its value to ...\instantclient_12_1, (not its containing folder!).
Add this same path to the "Path" environment variable.
Only now install cx_Oracle.
To help other people with the same problem:
This error tells about 32-64 bit mismatch between some DLL while importing module. Possibilities are:
Different architecture of Python and cx_Oracle (less probable since cx_Oracle installer on Windows warns you if appropriate Python was not found).
Different architecture of cx_Oracle libraries and oci.dll (more probable).
Keep in mind that cx_Oracle uses standart Oracle client (at OCI level), which must be installed on your machine. It searches for oci.dll in several places, including PATH. If it finds oci.dll of wrong version of the client, the error appears.
In case you get this error, check path list in the PATH environment variable. It is likely to contain path to BIN folder of wrong version of Oracle client. If you have several clients, specify in the PATH the appropriate one, or install the appropriate client.
NOTE: ORACLE_HOME does not have an effect for cx_Oracle. In my case only changing of PATH helped. I think the Ruben's solution works because of item 3 ('Add this same path to the "Path" environment variable').
I am using python35 64 bit and oracle express on win 7 (64 bit).
I installed cx_Oracle using pip3 (pip3 install cx_Oracle) instead of downloading the installer from pypi.
I faced the same problem.
I solved it by following above guidelines, but instead of 32 bit client, I downloaded the 64 bit version of the instant client (instantclient-basic-windows.x64-11.2.0.4.0.zip) from http://www.oracle.com/technetwork/topics/winx64soft-089540.html.
I then extracted it to c:\oraclexe. And added these environment variables
set ORACLE_BASE=C:\oraclexe
set ORACLE_HOME=C:\oraclexe\app\oracle\product\11.2.0\server
set PATH=C:\oraclexe\instantclient_11_2;%PATH%
And ran my django migrate commands:
python manage.py migrate
It worked excellent
Easy way:
Make sure you have installed cx-Oracle, I have cx_Oracle-5.1.3-11g.win32-py2.7.exe
Download, unzip instantclient_12_1 and move it to C:\Python27
Add environment variable C:\Python27\instantclient_12_1
Restart your computer
Same ImportError occured for setup of:
Windows 10 x64
Oracle Instant Client 12_1 x64
Python 2.7.11 x64
cx_Oracle cx_Oracle-5.2-12c.win-amd64-py2.7
I solved it copying msvcr100.dll file into <oracle_instant_client_dir>
Had this issue also, and it seems importing cx_Oracle (at least as of 5.1.2) will fail (with the same error) if you have any invalid/unreachable UNC paths in front of Oracle in the PATH environment variable.
Fixing the UNC path (which was unrelated to Oracle) resolved the problem.
If you're using conda as a package manager, one way to overcome the DLL issue it to install oracle-instantclient by doing a conda install oracle-instantclient. This fixed the dependency which I couldn't fix by manually installing Oracle's instant-client.
As is the second time I came to this question, I feel the need to post what I did:
I'm using:
Win 8 64 bits
Python 2.7
I had no success installing Python and cx_Oracle 64 bits.
It only worked when I tried 32 bits versions and followed #rob answer instructions
I had same issue with DLL load failed on my Windows machine.
installed oracle client, set variables, ran cx_Oracle-5.1.3-11g.win32-py2.7.exe file.
however when I installed cx_Oracle with easy_setup it fixed the problem.
C:\Python27\Scripts\easy_install.exe cx_Oracle-5.1.3-11g.win32-py2.7.exe
Steps I have followed :
Downloaded the smart client instantclient-basic-windows.x64-12.1.0.2.0.zip
Extracted and copied to #your directory#\instantclient_12_1
Above directory contains dll's
Append the PATH variable with #your directory#\instantclient_12_1 and created env variable ORACLE_HOME= #your directory#\instantclient_12_1
Download and install cx_Oracle-5.2.1-11g.win-amd64-py2.7.exe
Open idle type import cx_Oracle
if you're using Anaconda on Windows try:
conda install cx_oracle
on your cmd
-> this
I know this is an old post, but I had this problem today and none of the solutions worked. I figure this could work for others with the same problem as of now.
Python version : 2.7.15 (64 bits)
cx_Oracle version : 6.4.1
Oracle Instant Client : 18.3
I kept getting the following error even though I followed evry steps in the correct order :
cx_Oracle.DatabaseError: DPI-1047: Oracle Client library cannot be loaded
I solved it by downgrading my Oracle Instant Client version to 12.1