Caffe Import error: libopencv_highgui.so.3.3: cannot open shared object file: No such file or directory - caffe

I created a virtual environment for python2.7 and I installed caffe using the command conda install -c conda-forge caffe. But when I try to import caffe, its throwing the following error.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/data/home/eex608/.conda/envs/MyPython2.7Caffe/lib/python2.7/site-packages/caffe/__init__.py", line 1, in <module>
from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver, NCCL, Timer
File "/data/home/eex608/.conda/envs/MyPython2.7Caffe/lib/python2.7/site-packages/caffe/pycaffe.py", line 13, in <module>
from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \
ImportError: libopencv_highgui.so.3.3: cannot open shared object file: No such file or directory
Can anyone tell me how to resolve this error?
The package info after I installed caffe (if this info is useful to debug)
2018-10-08 23:07:03 (rev 1)
anaconda {5.3.0 -> custom}
blas {1.0 -> 1.1 (conda-forge)}
ca-certificates {2018.03.07 -> 2018.8.24 (conda-forge)}
certifi {2018.8.24 -> 2018.8.24 (conda-forge)}
h5py {2.8.0 -> 2.8.0 (conda-forge)}
harfbuzz {1.8.8 -> 1.7.6}
hdf5 {1.10.2 -> 1.10.1 (conda-forge)}
matplotlib {2.2.3 -> 2.2.3 (conda-forge)}
mkl-service {1.1.2 -> 1.1.2}
mkl_fft {1.0.4 -> 1.0.6 (conda-forge)}
mkl_random {1.0.1 -> 1.0.1 (conda-forge)}
numexpr {2.6.8 -> 2.6.6 (conda-forge)}
numpy {1.15.1 -> 1.15.2 (conda-forge)}
numpy-base {1.15.1 -> 1.15.2}
openssl {1.0.2p -> 1.0.2p (conda-forge)}
pyqt {5.9.2 -> 5.6.0}
pytables {3.4.4 -> 3.4.4 (conda-forge)}
qt {5.9.6 -> 5.6.3}
qtconsole {4.4.1 -> 4.4.1 (conda-forge)}
scikit-learn {0.19.2 -> 0.20.0 (conda-forge)}
scipy {1.1.0 -> 1.1.0 (conda-forge)}
+boost-1.66.0 (conda-forge)
+boost-cpp-1.66.0 (conda-forge)
+caffe-1.0 (conda-forge)
+ffmpeg-3.2.4 (conda-forge)
+gflags-2.2.1 (conda-forge)
+giflib-5.1.4 (conda-forge)
+glog-0.3.5 (conda-forge)
+jasper-1.900.1 (conda-forge)
+leveldb-1.18 (conda-forge)
+libgcc-7.2.0 (conda-forge)
+libgfortran-3.0.0 (conda-forge)
+libiconv-1.15 (conda-forge)
+libopenblas-0.3.3
+libprotobuf-3.5.2 (conda-forge)
+libwebp-0.5.2 (conda-forge)
+lmdb-0.9.22 (conda-forge)
+openblas-0.2.20 (conda-forge)
+opencv-3.4.1 (conda-forge)
+protobuf-3.5.2 (conda-forge)
+python-gflags-3.1.2 (conda-forge)
+python-leveldb-0.193 (conda-forge)
+x264-1!152.20180717 (conda-forge)

Related

AttributeError: module 'keras.api._v2.keras' has no attribute 'utils'

OS: MacOS Monterey (12.4)
Chip: Apple Silicon M1
Env: Conda 4.12.0
Python: 3.9.12
TensorFlow version: 2.9.0, installed through pip install tensorflow-macos
Error message:
Traceback (most recent call last):
File "/Users/okihita/PycharmProjects/TFFlowerClassification/main.py", line 20, in <module>
training_dataset = tf.keras.utils.image_dataset_from_directory(
AttributeError: module 'keras.api._v2.keras' has no attribute 'utils'
Here's my main.py code:
import pathlib
import tensorflow as tf
from PIL import Image
data_dir = pathlib.Path('aksara-batak/toba')
aksara = list(data_dir.glob('a/*'))
img_height = 30
img_width = 30
training_dataset = tf.keras.utils.image_dataset_from_directory(
data_dir,
validation_split=0.2,
subset="training",
seed=123,
image_size=(img_height, img_width)
)
Did I import the wrong version of TensorFlow?

Django 2.0 - Python3.6 - CentOS 7 - MySQL connections

i try to install my website on a webserver which is in CentOS 7 with Django 2.0.6 and Python 3.6.
I installed : mysql-connector = 2.1.6,
mysql-connector-python = 8.0.11,
MySQL-python = 1.2.5,
mysqlclient = 1.3.12,
PyMySQL = 0.8.1
And when i run this command :
python3.6 manage.py migrate
I have this error :
File "MYPYTHONPATH/python3.6/site-packages/django/db/backends/mysql/base.py", line 36, in <module>
raise ImproperlyConfigured("mysqlclient 1.3.3 or newer is required; you have %s" % Database.__version__)
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.3 or newer is required; you have 1.2.5
But in the base.py file :
try:
import MySQLdb as Database
except ImportError as err:
raise ImproperlyConfigured(
'Error loading MySQLdb module.\n'
'Did you install mysqlclient?'
) from err
from MySQLdb.constants import CLIENT, FIELD_TYPE # isort:skip
from MySQLdb.converters import conversions # isort:skip
# Some of these import MySQLdb, so import them after checking if it's installed.
from .client import DatabaseClient # isort:skip
from .creation import DatabaseCreation # isort:skip
from .features import DatabaseFeatures # isort:skip
from .introspection import DatabaseIntrospection # isort:skip
from .operations import DatabaseOperations # isort:skip
from .schema import DatabaseSchemaEditor # isort:skip
from .validation import DatabaseValidation # isort:skip
version = Database.version_info
if version < (1, 3, 3):
raise ImproperlyConfigured("mysqlclient 1.3.3 or newer is required; you have %s" % Database.__version__)
I dont understand what can i do for resolving this kind of problem !
I hope someone can help me on =)
Okay, i solved it with the answer of this thread.
No module named MySQLdb
pip install PyMySQL
and then add this two lines to your Project/Project/init.py
import pymysql
pymysql.install_as_MySQLdb()
Works on WIN and python 3.3+

Error while installing mysql-python using pip

Get the following error while installing mysql-python using pip
pip : 9.0.1
python : 2.7
OS : Mac OS Sierra 10.12.5
Some-MacBook-Air:~ itssuyog$ pip install mysql-python
Collecting mysql-python
Downloading MySQL-python-1.2.5.zip (108kB)
100% |████████████████████████████████| 112kB 257kB/s
Installing collected packages: mysql-python
Running setup.py install for mysql-python ... error
Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/hm/jbqvwv_n1sb46q_v9wvb3fh80000gp/T/pip-build-ThTb9v/mysql-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /var/folders/hm/jbqvwv_n1sb46q_v9wvb3fh80000gp/T/pip-jTh4C4-record/install-record.txt --single-version-externally-managed--compile:
running install
running build
running build_py
creating build
creating build/lib.macosx-10.12-intel-2.7
copying _mysql_exceptions.py -> build/lib.macosx-10.12-intel-2.7
creating build/lib.macosx-10.12-intel-2.7/MySQLdb
copying MySQLdb/__init__.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb
copying MySQLdb/converters.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb
copying MySQLdb/connections.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb
copying MySQLdb/cursors.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb
copying MySQLdb/release.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb
copying MySQLdb/times.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb
creating build/lib.macosx-10.12-intel-2.7/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb/constants
copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb/constants
running build_ext
building '_mysql' extension
creating build/temp.macosx-10.12-intel-2.7
cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/Cellar/mariadb/10.2.7_1/include/mysql -I/usr/local/Cellar/mariadb/10.2.7_1/include/mysql/.. -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.12-intel-2.7/_mysql.o
In file included from _mysql.c:44:
/usr/local/Cellar/mariadb/10.2.7_1/include/mysql/my_config.h:286:11: warning: 'SIZEOF_SIZE_T' macro redefined [-Wmacro-redefined]
#define SIZEOF_SIZE_T SIZEOF_LONG
^
/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pymacconfig.h:43:17: note: previous definition is here
# define SIZEOF_SIZE_T 8
^
_mysql.c:287:14: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
cmd_argc = PySequence_Size(cmd_args);
~ ^~~~~~~~~~~~~~~~~~~~~~~~~
_mysql.c:317:12: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
groupc = PySequence_Size(groups);
~ ^~~~~~~~~~~~~~~~~~~~~~~
_mysql.c:470:14: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
int j, n2=PySequence_Size(fun);
~~ ^~~~~~~~~~~~~~~~~~~~
_mysql.c:1127:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
len = mysql_real_escape_string(&(self->connection), out, in, size);
~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_mysql.c:1129:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
len = mysql_escape_string(out, in, size);
~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_mysql.c:1168:9: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
size = PyString_GET_SIZE(s);
~ ^~~~~~~~~~~~~~~~~~~~
/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/stringobject.h:92:32: note: expanded from macro 'PyString_GET_SIZE'
#define PyString_GET_SIZE(op) Py_SIZE(op)
^~~~~~~~~~~
/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/object.h:116:56: note: expanded from macro 'Py_SIZE'
#define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size)
~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
_mysql.c:1178:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
len = mysql_real_escape_string(&(self->connection), out+1, in, size);
~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_mysql.c:1180:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
len = mysql_escape_string(out+1, in, size);
~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_mysql.c:1274:11: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
if ((n = PyObject_Length(o)) == -1) goto error;
~ ^~~~~~~~~~~~~~~~~~
/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/abstract.h:434:25: note: expanded from macro 'PyObject_Length'
#define PyObject_Length PyObject_Size
^
_mysql.c:1466:10: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
len = strlen(buf);
~ ^~~~~~~~~~~
_mysql.c:1468:10: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
len = strlen(buf);
~ ^~~~~~~~~~~
_mysql.c:1504:11: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
len = strlen(buf);
~ ^~~~~~~~~~~
_mysql.c:1506:11: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
len = strlen(buf);
~ ^~~~~~~~~~~
_mysql.c:1589:10: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
if (how < 0 || how >= sizeof(row_converters)) {
~~~ ^ ~
_mysql.c:2005:42: error: no member named 'reconnect' in 'struct st_mysql'
if ( reconnect != -1 ) self->connection.reconnect = reconnect;
~~~~~~~~~~~~~~~~ ^
15 warnings and 1 error generated.
error: command 'cc' failed with exit status 1
----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/hm/jbqvwv_n1sb46q_v9wvb3fh80000gp/T/pip-build-ThTb9v/mysql-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /var/folders/hm/jbqvwv_n1sb46q_v9wvb3fh80000gp/T/pip-jTh4C4-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/hm/jbqvwv_n1sb46q_v9wvb3fh80000gp/T/pip-build-ThTb9v/mysql-python/
I got a similar post on Stack Overflow : can't pip install mysql-python
That is for Ubuntu. But still I tried to install python-dev as suggested in the answer of that post using pip and got the following error :
Some-MacBook-Air:~ itssuyog$ sudo pip install python-dev
Password:
The directory '/Users/admin/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/admin/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check thepermissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting python-dev
Downloading python-dev-4.1.0.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/tmp/pip-build-mFlFdp/python-dev/setup.py", line 90, in <module>
evalall()
File "/private/tmp/pip-build-mFlFdp/python-dev/setup.py", line 86, in evalall
print("安装完成!")
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-build-mFlFdp/python-dev/
Thanx in advance!!
python-dev is the wrong python-dev; it seems some rogue Chineeze took the name and created a package that installs a backdoor.
Real python-dev is a development package for Debian/Ubuntu installable with apt. You don't need it in MacOS. If you have done brew install python (or python3) you should already have all necessary development files.
Try installing mysql-connector:
brew install mysql-connector-c

Getting 'File' is not a type identifier in Cython when trying to define a File pointer

My directory structure
kents-air:Cython-Test kent$ tree
.
├── main.py
├── setup.py
└── test
├── test.c
└── test.pyx
1 directory, 4 files
test.pyx
from libc.stdio cimport FILE
cdef class RandomTest:
cdef File * reader
cdef int number
def __init__(self, number):
self.number = number
def print_random(self):
print(self.number)
main.py
from .test import RandomTest
tester = RandomTest(5)
tester.print_random()
setup.py
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize(["test/*.pyx"]),
)
Output
pythkents-air:Cython-Test kent$ python3 setup.py build_ext
Compiling test/test.pyx because it changed.
[1/1] Cythonizing test/test.pyx
Error compiling Cython file:
------------------------------------------------------------
...
from libc.stdio cimport FILE
cdef class RandomTest:
cdef File * reader
^
------------------------------------------------------------
test/test.pyx:4:9: 'File' is not a type identifier
Traceback (most recent call last):
File "setup.py", line 5, in <module>
ext_modules = cythonize(["test/*.pyx"]),
File "/usr/local/lib/python3.5/site-packages/Cython/Build/Dependencies.py", line 912, in cythonize
cythonize_one(*args)
File "/usr/local/lib/python3.5/site-packages/Cython/Build/Dependencies.py", line 1034, in cythonize_one
raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: test/test.pyx
Version Info
kents-air:Cython-Test kent$ python3
Python 3.5.1 (default, Apr 18 2016, 11:46:32)
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Cython==0.24
Links I have already checked:
Declaring FILE pointers in Cython
Pass file handle to cython function

How to use nltk3 for python33?

I successfully installed NLTK 2.0.4, but when I tried to download the NLTK packages, i.e.
nltk.download('stopwords')
it doesn't work, so I am trying to install an updated version of NLTK for python 3 but it gives this error:
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Prashant\AppData\Roaming\Python\Python33\site-packages\nltk\_
nit__.py", line 37
except IOError, ex:
^
SyntaxError: invalid syntax
Is there any way to install NLTK for python33?
First install python3-pip then use it to install pyyaml
$ sudo apt-get install python3-pip
$ sudo pip3 install pyyaml
$ wget http://www.nltk.org/nltk3-alpha/nltk-3.0a3.tar.gz
$ tar -xzvf nltk-3.0a3.tar.gz
$ cd nltk-3.0a3/
$ sudo python3 setup.py install
$ python3
>>> import nltk
>>> from nltk.corpus import brown
>>> print(brown.sents()[0])
['The', 'Fulton', 'County', 'Grand', 'Jury', 'said', 'Friday', 'an', 'investigation', 'of', "Atlanta's", 'recent', 'primary', 'election', 'produced', '``', 'no', 'evidence', "''", 'that', 'any', 'irregularities', 'took', 'place', '.']