Where to find PyUnicodeUCS4_Decode? - python

I am trying to test some 32 bit software on an Ubuntu 11.04 64 bit machine. After getting the 32 bit libraries installed, it now fails with :
Python 2.7.2 (default, Nov 4 2011, 19:26:59)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyexpat import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /usr/local/lib/python2.7/lib-dynload/pyexpat.so: undefined symbol: PyUnicodeUCS4_Decode
Any ideas on where to find PyUnicodeUCS4_Decode? I installed PyXML-0.8.4, but that didn't help.
Thanks !

This thread seemed to explain that it might be due to python supporting two different Unicode modes UCS2 (the default), and UCS4. It suggests recompiling from scratch.
You can download the package directly and then compile on your machine by running:
python setup.py build
python setup.py install

Related

Python Import Different Libraries from Different Versions

I'm trying to develop a Python script, and I seem to be running into a conflict between two of the libraries that I want to include.
The first dependency that I have is pymoos (https://github.com/msis/python-moos), which is necessary to connect to my communication architecture. I've built the code and manually installed the resultant pymoos.so in the following places:
/usr/lib/python3.6/site-packages/pymoos.so
/usr/lib64/python2.7/lib-dynload/pymoos.so
/usr/lib64/python3.6/lib-dynload/pymoos.so
/usr/local/lib/python3.7/lib-dynload/pymoos.so
However, only python2.7 will allow me to 'import pymoos' from the interpreter. Attempting from either of the Python3 versions produces this:
Python 3.6.8 (default, Jun 11 2019, 15:15:01)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymoos
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define module export function (PyInit_pymoos)
The second dependency is pydantic, which I have only managed to install using pip3, apparently meaning that it's only available from either of the versions of Python3 that I have installed. Attempting to import from Python2 gives the following:
Python 2.7.5 (default, Jun 11 2019, 14:33:56)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pydantic
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pydantic
Since I know where the pymoos.so library is, I think that my easiest path forward is to put that in the right place so it works with python3, but I can't seem to find the right place!
as per my comment:
it should be as simple as pip install path/to/pymoos/code, but you might be better off using a more widely used database library like asyncpg or psycopg.
Regarding having to use sudo, you might consider using virtualenv or similar to setup a dedicated python environment for your application.

How to bind openalpr with python on a mac?

I recently installed openalpr on my mac using brew install openalpr with success. I would like to use the openalpr library with python 2.7 but I am having difficulty binding the two and could use some help.
I currently get the following in my projects file location:
Python 2.7.11 (default, Jan 22 2016, 08:29:18)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from openalpr import Alpr
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named openalpr
>>>
When I move to /usr/local/Cellar/openalpr/2.3.0/lib/python2.7/dist-packages/openalpr
The import works. How can I bind this library? Thanks
EDIT: I think I've seen that running the setup.py for openalpr is how you bind but I have no idea where to find it in my file system.
I had to do the following command:
echo /usr/local/opt/openalpr/lib/python2.7/dist-packages/ >> /usr/local/lib/python2.7/site-packages/openalpr.pth

Compile OpenCV for Python wit contrib modules on Windows 10 using Visual Studio 2013

I want to install OpenCV 3 with contrib modules on windows 10 and use it with Python 2.7 (32 bits). I think that the only way to have contrib modules in opencv is compiling it. (not installing with *.exe).
I have compiled OpenCV with contrib modules without problems. I have used Visual Studio 2013, compiling in release mode (for Win32).
After compile OpenCV, I can see the "cv2.pyd" module in $PYTHON_HOME/Libs/site-packages
The problem:
When I try to import cv2 in Python IDLE I have this error:
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed: The specified module could not be found.
As you can see, I have a 32 bits Python. Also, the module is "detected".
What's the problem?
I have found the problem.
I had to add the OpenCV *.dll to PATH environment variable. This *.dll are in
$OPENCV_HOME/bin/release

Fedora: No module named 'ZODB' in Python 3

How can I install ZODB for Python 3? I installed python-ZODB3 in Fedora, but I can use ZODB only in Python 2:
$ python
Python 2.7.5 (default, Sep 25 2014, 13:57:38)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ZODB
>>> quit()
$ python3
Python 3.3.2 (default, Jun 30 2014, 17:20:03)
[GCC 4.8.3 20140624 (Red Hat 4.8.3-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ZODB
Traceback (most recent call last):
File "/usr/lib64/python3.3/code.py", line 90, in runcode
exec(code, self.locals)
File "<console>", line 1, in <module>
ImportError: No module named 'ZODB'
Which package am I missing?
In general, the Fedora name for Python package foo for Python 3.x is python3-foo, not python-foo3.
In particular, python-ZODB3 is the Python 2.x package for ZODB3. (ZODB3 is the obsolete version 3 of ZODB, still provided for backward compatibility.) Both the old 3.x and new 4.x versions of ZODB work for both Python 2.x and 3.x; that means there are (at least potentially) packages named python-ZODB (ZODB 4.x for Python 2.x), python3-ZODB (4.x for 3.x), python-ZODB3 (3.x for 2.x), and python3-ZODB3 (3.x for 3.x). It's the second one you want, not the third.
I can't guarantee that your Fedora version and repos have a python3-ZODB RPM, but from a quick search, I found this, so at least some Fedora-based systems have one.
If there's not a Fedora RPM for that, you can probably install it via pip, something like pip3 install ZODB.

cx_Oracle problem trying to import python

I am trying to run python in an Apache WS in a linux RHEL x86_64.
After Install and configure Python2.5 and Apache, I install Oracle Instant Client (basic and sdk) in a by an .rpm file withou any problem.
oracle-instantclient-basic-10.2.0.4-1.x86_64.rpm
oracle-instantclient-devel-10.2.0.4-1.x86_64.rpm
I set the envoirment variables
export ORACLE_HOME=/appl/paths/instantclient_10_2
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:$PATH
Then install cx_Oracle by an .rpm file too and again withou any problem.
cx_Oracle-5.0.3-10g-unicode-py25-1.x86_64.rpm
When I try to import cx_Oracle in python I got the message
Python 2.5.2 (r252:60911, Jul 1 2010, 17:47:36)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /appl/paths/python2.5/site-packages/cx_Oracle.so: undefined symbol: OCIDBShutdown
I google for answers without success. Any tip?
The problem was in the ORACLE_HOME, there was a misspelling on it
I solved the same problem by installing an older version of cx_Oracle (4.3.1 instead of 5.1.2). Just for future reference.

Categories