How to call OCRopus software, or any conflicting software, from Matlab? - matlab

When calling the OCR software OCRopus directly from Matlab prompt, there is a series of errors that would not appear when the software is called directly from the shell prompt:
>> ! gnome-terminal -x bash ./sampleBash.sh
Traceback (most recent call last):
File "/usr/local/bin/ocropus-gpageseg", line 15, in <module>
from pylab import *
File "/usr/lib/pymodules/python2.7/pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "/usr/lib/pymodules/python2.7/matplotlib/__init__.py", line 156, in <module>
from matplotlib.cbook import is_string_like
File "/usr/lib/pymodules/python2.7/matplotlib/cbook.py", line 28, in <module>
import numpy as np
File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 153, in <module>
from . import add_newdocs
File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 18, in <module>
from .polynomial import *
File "/usr/lib/python2.7/dist-packages/numpy/lib/polynomial.py", line 19, in <module>
from numpy.linalg import eigvals, lstsq, inv
File "/usr/lib/python2.7/dist-packages/numpy/linalg/__init__.py", line 50, in <module>
from .linalg import *
File "/usr/lib/python2.7/dist-packages/numpy/linalg/linalg.py", line 29, in <module>
from numpy.linalg import lapack_lite, _umath_linalg
ImportError: /opt/MATLAB/R2012b/sys/os/glnxa64/libgfortran.so.3: version `GFORTRAN_1.4' not found (required by /usr/lib/liblapack.so.3)
where sampleBash.sh is:
#!/bin/bash -e
FILENAME='testfile.png'
ocropus-gpageseg --usefilename "$FILENAME"
$SHELL
It seems that there is a clash between Matlab's environment variables and those of the system bash shell. Any idea on how to send a 'clean' shell environment to the OCRopus software (or any other similar software)?
This is not limited to the OCRopus calls, and any software that would conflict with the Matlab environment variables set during the shell call from within Matlab would face the same problem.
Thanks.

A not-so-clean solution could be to remove the clashing variables before calling the OCRopus software:
>> ! gnome-terminal -x bash unset OSG_LD_LIBRARY_PATH; unset XAPPLRESDIR; unset XKEYSYMDB; unset LD_LIBRARY_PATH; unset TOOLBOX; unset XFILESEARCHPATH; unset BASEMATLABPATH; ./sampleBash.sh
In this way, variables such as OSG_LD_LIBRARY_PATH are removed from the environment before calling the OCR software.

Related

I run odoo 15 on vs-code but these errors appear what the solution for these?

The errors is:
( /usr/bin/env /bin/python3 /home/abdulrahman/.vscode/extensions/ms-python.python-2022.16.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher 37511 -- /home/abdulrahman/odoo/odoo-15.0/odoo-bin --config=/home/a /usr/bin/env /bin/python3 /home/abdulrahman/.vscode/extensions/ms-python.python-2022.16.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher 37511 -- /home/abdulrahman/odoo/odoo-15.0/odoo-bin --config=/home/abdulrahman/odoo/config/odoo15.conf
Traceback (most recent call last):
File "/home/abdulrahman/odoo/odoo-15.0/odoo-bin", line 5, in
import odoo
File "/home/abdulrahman/odoo/odoo-15.0/odoo/init.py", line 113, in
from . import modules
File "/home/abdulrahman/odoo/odoo-15.0/odoo/modules/init.py", line 8, in
from . import db, graph, loading, migration, module, registry
File "/home/abdulrahman/odoo/odoo-15.0/odoo/modules/graph.py", line 10, in
import odoo.tools as tools
File "/home/abdulrahman/odoo/odoo-15.0/odoo/tools/init.py", line 8, in
from . import pdf
File "/home/abdulrahman/odoo/odoo-15.0/odoo/tools/pdf.py", line 18, in
from odoo.tools.misc import file_open
File "/home/abdulrahman/odoo/odoo-15.0/odoo/tools/misc.py", line 35, in
import babel
File "/home/abdulrahman/.local/lib/python3.10/site-packages/babel/init.py", line 20, in
from babel.core import UnknownLocaleError, Locale, default_locale, \
File "/home/abdulrahman/.local/lib/python3.10/site-packages/babel/core.py", line 14, in
from babel import localedata
File "/home/abdulrahman/.local/lib/python3.10/site-packages/babel/localedata.py", line 17, in
from collections import MutableMapping
ImportError: cannot import name 'MutableMapping' from 'collections' (/usr/lib/python3.10/collections/init.py)bdulrahman/odoo/config/odoo15.conf
Traceback (most recent call last):
File "/home/abdulrahman/odoo/odoo-15.0/odoo-bin", line 5, in
import odoo
File "/home/abdulrahman/odoo/odoo-15.0/odoo/init.py", line 113, in
from . import modules
File "/home/abdulrahman/odoo/odoo-15.0/odoo/modules/init.py", line 8, in
from . import db, graph, loading, migration, module, registry
File "/home/abdulrahman/odoo/odoo-15.0/odoo/modules/graph.py", line 10, in
import odoo.tools as tools
File "/home/abdulrahman/odoo/odoo-15.0/odoo/tools/init.py", line 8, in
from . import pdf
File "/home/abdulrahman/odoo/odoo-15.0/odoo/tools/pdf.py", line 18, in
from odoo.tools.misc import file_open
File "/home/abdulrahman/odoo/odoo-15.0/odoo/tools/misc.py", line 35, in
import babel
File "/home/abdulrahman/.local/lib/python3.10/site-packages/babel/init.py", line 20, in
from babel.core import UnknownLocaleError, Locale, default_locale, \
File "/home/abdulrahman/.local/lib/python3.10/site-packages/babel/core.py", line 14, in
from babel import localedata
File "/home/abdulrahman/.local/lib/python3.10/site-packages/babel/localedata.py", line 17, in
from collections import MutableMapping
ImportError: cannot import name 'MutableMapping' from 'collections' (/usr/lib/python3.10/collections/init.py))
This is the errors i want the solutions for it.
Hi I'm not sure if it's the proper solution but I experienced some difficulty with my python version and when I downgraded the version (to py3.9) it worked. You can Try it too. Also I suggest to check your launch.json configurations and make sure that all the paths and names have been set correctly.

How to use the ibm_boto3 in python

Who has the same problem?
I want to store data in cos, but cannot use the ibm_boto3 on my machine.
To be sure to check with a sample, I used the code from the sample from this ibm-cos-sdk github.
Installed
pip3 freeze
backports.functools-lru-cache==1.5
botocore==1.12.28
docutils==0.14
futures==3.1.1
ibm-cos-sdk==2.3.2
ibm-cos-sdk-core==2.3.2
ibm-cos-sdk-s3transfer==2.3.2
-e git://github.com/boto/jmespath.git#1c9c35cf681b6605d8629e5ce8865221a4fd2a30#egg=jmespath
mock==1.3.0
nose==1.3.3
pbr==5.0.0
python-dateutil==2.7.3
s3transfer==0.1.13
six==1.11.0
urllib3==1.23
Here is my cli result and as you can see the ibm_boto3 is not found.
python3 test.py
Traceback (most recent call last):
File "test.py", line 1, in <module>
import ibm_boto3
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ibm_boto3/__init__.py", line 16, in <module>
from ibm_boto3.session import Session
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ibm_boto3/session.py", line 27, in <module>
import ibm_botocore.session
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ibm_botocore/session.py", line 37, in <module>
import ibm_botocore.credentials
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ibm_botocore/credentials.py", line 36, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
Yeah, it looks like requests somehow fell out of the requirements file in the latest release. The team is patching it and will release an update soon.
In the meantime, you can manually install the package in your environment with pip3 install requests or by manually adding it to the requirements.txt file:
echo "requests==2.18.0" >> path/to/requirements.txt

Import Error of IBM Watson Natural Language Understanding API

I am now trying to extract keywords by using IBM Watson Natural Language Understanding API. I follow the instruction and have installed the watson_developer_cloud. However, I met an error when import the NaturalLanguageUnderstandingV1. Could you help me with it? Thank you!
from watson_developer_cloud import NaturalLanguageUnderstandingV1
Traceback (most recent call last):
File "<ipython-input-11-ab5aa6f014f4>", line 1, in <module>
from watson_developer_cloud import NaturalLanguageUnderstandingV1
File "C:\Users\yipin\Anaconda3\envs\tensorflow\lib\site-
packages\watson_developer_cloud\__init__.py", line 30, in <module>
rom .speech_to_text_v1 import SpeechToTextV1
File "C:\Users\yipin\Anaconda3\envs\tensorflow\lib\site-
packages\watson_developer_cloud\speech_to_text_v1.py", line 74, in <module>
from watson_developer_cloud.websocket import RecognizeCallback, RecognizeListener
File "C:\Users\yipin\Anaconda3\envs\tensorflow\lib\site-packages\watson_developer_cloud\websocket\__init__.py", line 18, in <module>
from .speech_to_text_websocket_listener import RecognizeListener
File "C:\Users\yipin\Anaconda3\envs\tensorflow\lib\site-packages\watson_developer_cloud\websocket\speech_to_text_websocket_listener.py", line 21, in <module>
from twisted.internet import ssl, reactor
File "C:\Users\yipin\Anaconda3\envs\tensorflow\lib\site-packages\twisted\internet\ssl.py", line 59, in <module>
from OpenSSL import SSL
File "C:\Users\yipin\Anaconda3\envs\tensorflow\lib\site-packages\OpenSSL\__init__.py", line 8, in <module>
from OpenSSL import crypto, SSL
File "C:\Users\yipin\Anaconda3\envs\tensorflow\lib\site-packages\OpenSSL\crypto.py", line 16, in <module>
from OpenSSL._util import (
File "C:\Users\yipin\Anaconda3\envs\tensorflow\lib\site-packages\OpenSSL\_util.py", line 6, in <module>
from cryptography.hazmat.bindings.openssl.binding import Binding
File "C:\Users\yipin\Anaconda3\envs\tensorflow\lib\site-packages\cryptography\hazmat\bindings\openssl\binding.py", line 13, in <module>
from cryptography.hazmat.bindings._openssl import ffi, lib
ImportError: DLL load failed: The operating system cannot run %1.
After reinstalling the watson-cloud-developer as an administrator. I solve the problem. It seems that if we do not run the pip install command as an administrator, then the package cannot be installed correctly.

pylint errors when using liclipse

PyLint: Executing command line: /usr/local/bin/pylint --rcfile=/Users/amansehgal/.rcfile --include-ids=y /Users/amansehgal/Documents/cis519/hw3_skeleton/boostedDT.py
PyLint: The stdout of the command line is:
PyLint: The stderr of the command line is: Traceback (most recent call last):
File "/usr/local/bin/pylint", line 11, in <module>
sys.exit(run_pylint())
File "/Library/Python/2.7/site-packages/pylint/__init__.py", line 12, in run_pylint
from pylint.lint import Run
File "/Library/Python/2.7/site-packages/pylint/lint.py", line 34, in <module>
import astroid
File "/Library/Python/2.7/site-packages/astroid/__init__.py", line 54, in <module>
from astroid.nodes import *
File "/Library/Python/2.7/site-packages/astroid/nodes.py", line 54, in <module>
from astroid.scoped_nodes import (
File "/Library/Python/2.7/site-packages/astroid/scoped_nodes.py", line 25, in <module>
import io
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in <module>
import _io
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
PyLint: Executing command line: /usr/local/bin/pylint --rcfile=/Users/amansehgal/.rcfile --include-ids=y /Users/amansehgal/Documents/cis519/hw3_skeleton/boostedDT.py
PyLint: The stdout of the command line is:
PyLint: The stderr of the command line is: Traceback (most recent call last):
File "/usr/local/bin/pylint", line 11, in <module>
sys.exit(run_pylint())
File "/Library/Python/2.7/site-packages/pylint/__init__.py", line 12, in run_pylint
from pylint.lint import Run
File "/Library/Python/2.7/site-packages/pylint/lint.py", line 34, in <module>
import astroid
File "/Library/Python/2.7/site-packages/astroid/__init__.py", line 54, in <module>
from astroid.nodes import *
File "/Library/Python/2.7/site-packages/astroid/nodes.py", line 54, in <module>
from astroid.scoped_nodes import (
File "/Library/Python/2.7/site-packages/astroid/scoped_nodes.py", line 25, in <module>
import io
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in <module>
import _io
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
I get this error when trying to run pyLint in LiClipse and using the option redirect messages to console. I ran the line on a command prompt without any errors. So the issue is with LiClipse no redirecting output properly. Any ideas ?
/usr/local/bin/pylint --rcfile=/Users/amansehgal/.rcfile --include-ids=y /Users/amansehgal/Documents/cis519/hw3_skeleton/boostedDT.py
This usually means that the console env is different from the LiClipse env.
To fix it, print the environment variables from inside LiClipse and from the shell.
You can do that by creating a python script such as:
for key, val in sorted(os.environ.items()):
print('%s:\n %s' % (key, '\n '.join(sorted(val.split(os.pathsep)))))
And then comparing the values you have in either case.
The most common issue would be in the PATH, PYTHONPATH, DYLD_LIBRARY_PATH (on mac) or LD_LIBRARY_PATH (on linux) env variables.
You can also try to start LiClipse from the same shell where you started your command so that it inherits the env variables you have from the shell.

google-cloud-storage library from nosetests using testbed

I have google-cloud-storage pip installed into a lib directory and vendored in. It's running just fine locally during development of my python appengine app. However, when trying to run unit tests via nose and testbed I'm getting "The 'google-cloud-core' distribution was not found and is required by the application". Here is the stack:
Traceback (most recent call last):
File "/Users/jason/dev/gain-data/venv/lib/python2.7/site-packages/nose/loader.py", line 418, in loadTestsFromName
addr.filename, addr.module)
File "/Users/jason/dev/gain-data/venv/lib/python2.7/site-packages/nose/importer.py", line 47, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/Users/jason/dev/gain-data/venv/lib/python2.7/site-packages/nose/importer.py", line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/Users/jason/dev/gain-data/data/storage/__init__.py", line 4, in <module>
from google.cloud.storage import Blob, Client
File "/Users/jason/dev/gain-data/lib/google/cloud/storage/__init__.py", line 42, in <module>
from google.cloud.storage.batch import Batch
File "/Users/jason/dev/gain-data/lib/google/cloud/storage/batch.py", line 30, in <module>
from google.cloud.storage.connection import Connection
File "/Users/jason/dev/gain-data/lib/google/cloud/storage/connection.py", line 17, in <module>
from google.cloud import connection as base_connection
File "/Users/jason/dev/gain-data/lib/google/cloud/connection.py", line 31, in <module>
get_distribution('google-cloud-core').version)
File "/Users/jason/dev/gain-data/venv/lib/python2.7/site-packages/pkg_resources/__init__.py", line 557, in get_distribution
dist = get_provider(dist)
File "/Users/jason/dev/gain-data/venv/lib/python2.7/site-packages/pkg_resources/__init__.py", line 431, in get_provider
return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
File "/Users/jason/dev/gain-data/venv/lib/python2.7/site-packages/pkg_resources/__init__.py", line 968, in require
needed = self.resolve(parse_requirements(requirements))
File "/Users/jason/dev/gain-data/venv/lib/python2.7/site-packages/pkg_resources/__init__.py", line 854, in resolve
raise DistributionNotFound(req, requirers)
DistributionNotFound: The 'google-cloud-core' distribution was not found and is required by the application
Any thoughts?
I had the same issue with google-cloud-translate, I was forced to also install the package "globally", i.e. pip install google-cloud-translate.
After struggling a lot with this same issue I found out that the error was because the vendor pip lib wasn't in the PYTHONPATH before calling the nosetests.
Try adding the vendor lib to the PYTHONPATH and then run the tests.
export PYTHONPATH="$(HOME)/Projects/myproject/pip_lib:$$PYTHONPATH"; \
nosetests .