ImportError when importing cx_Oracle with PyPy - python

I was previously using python to pass multiple queries to an Oracle Database but the script took too long to execute. So I decided to opt for PyPy and use the JIT Compiler rather than the CPython interpreter. I installed PyPy via apt and then compiled the script with the command:
pypy script_file.py
It returned back the following error:
import cx_Oracle
ImportError: No module named cx_Oracle
Is cx_Oracle not supported by PyPy or am I doing something incorrectly? If it is, is this due to an issue with the environment values and how can I set it right?
Thank you for the help! Sorry for the bad English.

Regardless of PyPy support, each connection to Oracle Database will still only ever be able to execute one statement at a time. You could stick with CPython and look at other architectures such as opening multiple connections. Also tune your queries and tune how cx_Oracle fetches data, eg. with arraysize and the (new in cx_Oracle 8) prefetchrows. See the cx_Oracle manual section Tuning cx_Oracle.

Related

Problem upgrading Sqlite3 version on CentOS for Python

I have CentOS 6 on my system and I'm trying to update SQLite for Python. I've installed it from source and executing sqlite --version returns version 3.33.0 as expected.
However, when I try to check the python SQLite version using import sqlite3; sqlite3.sqlite_version; I still get the previous SQLite version 3.6.20.
Software Locations:
Python 3.6.9 - /usr/bin/python3
Sqlite3 - /usr/bin/sqlite3
I've tried the solution here, this does not work at all, after updating LD_LIBRARY_PATH and checking the python SQLite version it still gives '3.6.20', and here, when I try sudo LD_RUN_PATH=, it gives me the error No such file or directory, but when I execute it without sudo LD_RUN_PATH=, it successfully compiles but still gives me SQLite '3.6.20' (Compiled python without uninstalling).
Note: I have multiple python3 versions.
What can I do to resolve this?
When I did it (specifically trying to find a way to update sqlite3 for a running python program; did not work...), I compiled sqlite and got libsqlite3.so.0.8.6, and then replaced the system-wide sqlite3 with that. For me on debian, that was in /usr/lib/x86_64-linux-gnu. I did see (though now I can't find where) that this way may cause issues when updating in the future. It did update python's sqlite3 for me though.
You can import specific versions:
__requires__= 'sqlite3==3.6.20'
import pkg_resources
pkg_resources.require("sqlite3==3.6.20")
import sqlite
Note that this only works on the first import. If sqlite gets imported before pkg_resources, it will take the latest version.

Oracle DPI-1047 on macOS 10.14.6 with Python 2.7.10

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!

cx_Oracle 5.1.1 under apache+mod_wsgi

if I use cx_Oracle 5.0.4, I can connect from python console, and works under apache+django+mod_wsgi
but when I update cx_Oracle 5.1.1, I can connect from python console, BUT same code doesn't work under apache+django+mod_wsgi
File "C:\Python27\lib\site-packages\django\db\backends\oracle\base.py", line 24, in
raise ImproperlyConfigured("Error loading cx_Oracle module: %s" % e)
TemplateSyntaxError: Caught ImproperlyConfigured while rendering: Error loading cx_Oracle module: DLL load failed: The specified module could not be found.
PS: python 2.7
PSS: I have instaled MSVC 2008 Redistributable x86
Need a solution as well.
I have the same setup on WinXP (Apache 2.2.21/ mod_wsgi 3.3/ python 2.7.2/ cx_Oracle 5.x.x). I found that cx_Oracle 5.1 also fails with the same error. Only 5.0.4 works.
Here is the list of changes that were made from 5.0.4 to 5.1:
Remove support for UNICODE mode and permit Unicode to be passed through in
everywhere a string may be passed in. This means that strings will be
passed through to Oracle using the value of the NLS_LANG environment
variable in Python 3.x as well. Doing this eliminated a bunch of problems
that were discovered by using UNICODE mode and also removed an unnecessary
restriction in Python 2.x that Unicode could not be used in connect strings
or SQL statements, for example.
Added support for creating an empty object variable via a named type, the
first step to adding full object support.
Added support for Python 3.2.
Account for lib64 used on x86_64 systems. Thanks to Alex Wood for supplying
the patch.
Clear up potential problems when calling cursor.close() ahead of the
cursor being freed by going out of scope.
Avoid compilation difficulties on AIX5 as OCIPing does not appear to be
available on that platform under Oracle 10g Release 2. Thanks to
Pierre-Yves Fontaniere for the patch.
Free temporary LOBs prior to each fetch in order to avoid leaking them.
Thanks to Uwe Hoffmann for the initial patch.

Error when importing cx_Oracle module [Python]

I use Windows 7 64 bit and Oracle 10g. I have installed python-2.7.2.amd64 and cx_Oracle-5.1-10g.win-amd64-py2.7.
When I importing cx_Oracle module I get this error:
Traceback (most recent call last):
File "C:\Osebno\test.py", line 1, in
import cx_oracle
ImportError: No module named cx_oracle
Can someone please tell me what is wrong?
Have you tried import cx_Oracle (upper-case O) instead of import cx_oracle?
I had this same issue under Windows.
I used Dependency Walker to open up the cx_Oracle.pyd file in C:\Python\Libs\site-libraries\ and reviewed the findings that dependency walker gave.
Dependency Walker showed me that in this case I had the x86 version of Python 2.7.2 installed and x64 version of the Oracle client & client DLL (oci.dll) and was trying to use the x64 version of the cx_Oracle module. With that knowledge I installed Python 2.7.2 x86_64 for Windows and everything was right as rain.
The alternative was to install the x86 version of the Oracle client & cx_Oracle which is much more of a PITA than installing a new Python interpreter.
Also, as this was news to me, you must have the Oracle client installed as well as it provides the 'OCI.dll' client library that cx_Oracle uses. It's located here: Oracle Client Installer Windows x64. Probably helps if one reads the documentation. ;)
Either way, Dependency walker could give you a big clue as to what your issue is if you're having import errors. Unfortunately on-import error messages can be quite ambiguous. I received the same error you referenced and number of other less than specific errors as well.
after installing the cx_Oracle download the instant client form oracle owth all DLLs , then copy then in the same directory of cx_Oracle.pyd , it will work directly
tried and worked for me.
It's not finding the module.
Things to investigate: Do you have several python installations? Did it go to the right one? Do a global search for cx_oracle and see if it's in the correct place. Check your PYTHONPATH variable. Check Python's registry values HKLM\Software\Python\Pyhoncore. Are they correct?
See this answer: https://stackoverflow.com/a/19552263/496289
ignore this.... making up other 17 bytes that're needed to make this post long enough...

Accessing a MySQL database from python

I have been trying for the past several hours to find a working method of accessing a mysql database in python. The only thing that I've managed to get to compile and install is pyodbc but the necessary driver is not available for ppc leopard.
I already know about this.
UPDATE:
I've gotten setuptools to install, but now MySQL-python won't build.
UPDATE:
Now I've gotten sqlalchemy to install but while it will show up when called by the command line it won't import when used in my cgi script.
Try SQL Alchemy.
It is awesome.
Install fink. It includes the MySQLdb package.
UPDATE: Now I've gotten sqlalchemy to
install but while it will show up when
called by the command line it won't
import when used in my cgi script.
Can you verify that the Python being invoked from your CGI script is the same as the one you get when you run Python interactively? Check which python and compare it to your webserver CGI settings. That's the only thing I can think of that would cause this - getting it installed in one Python but not the other.
What OS are you on? If you're on something like Ubuntu, sudo apt-get install python-mysqldb is much more reliable than trying to build it yourself.
Also, unless I'm mistaken, SQLAlchemy won't actually help you make the connection itself if you don't have a DB-API2 module (like python-mysqldb) installed - SQLAlchemy sits at the next level up, using the DB-API2 connection and making access to it more Pythonic.

Categories

Resources