Importing torch failed when lazyimported cv2 first - opencv

I am using self-compiled python 3.6.3 (link) on Ubuntu 14.04. My torch is 1.0.1.post2, Tensorlayer 1.10.1. To reproduce my issue, try with
from tensorlayer.lazy_imports import LazyImport
cv2 = LazyImport("cv2")
import torch
It fails with,
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/torch/__init__.py", line 84, in <module>
from torch._C import *
ImportError: dlopen: cannot load any more object with static TLS
My torch is installed with pip install torch torchvision. Also before compiling Python, I did apt-get install tk8.6-dev in order to make python configured with tkinter. The reason why I compile Python on my own is that shipped apt-get install-ed Python is incompatible with tkinter somehow, even with packages installed, it errs at importing too.
I wish not to change the importing order at it surely works. I hope to find out the real cause of it. Many thanks in advance!

Related

Cannot import opencv after succesfull install on Raspberry Pi

I try to install opencv on my Raspberry Pi with 4GB RAM (Raspberry OS version Linux 5.15.84-v8+ aarch64). Instructions I found on q-engineering. After a 2hr lasting build process the make announced that opencv was succesfully installed. When I try to import it I get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'
But opencv appears to be succesfully installed. When I run opencv_version I got:
$ opencv_version
4.7.0-dev
and:
/usr/local/bin/opencv_visualisation
/usr/local/bin/opencv_annotation
/usr/local/bin/opencv_version
/usr/local/bin/opencv_model_diagnostics
/usr/local/bin/opencv_waldboost_detector
/usr/local/bin/opencv_interactive-calibration
/usr/local/share/licenses/opencv4
/usr/local/share/opencv4
/usr/local/lib/aarch64-linux-gnu/cmake/opencv4
/usr/local/lib/aarch64-linux-gnu/pkgconfig/opencv4.pc
/usr/local/include/opencv4
/usr/local/include/opencv4/opencv2
/usr/local/include/opencv4/opencv2/opencv.hpp
/usr/local/include/opencv4/opencv2/gapi/opencv_includes.hpp
/usr/local/include/opencv4/opencv2/opencv_modules.hpp
Looking for cv2 or *cv2* yielded nothing except what was already listed above. The date/time of the files conform to the time I ran the install script.
Next I tried opencv-lite according to instructions from the same source. Same result: succesful installation, traces of newly put opencv files but import cv2 still fails.
To complicate matters I use anaconda environments. I got two: base and rpi. I installed with rpi activated. In both no trace of opencv or cv2 and in both cases import fails. Some information where the system fetches python:
$ which python
/home/arnold/bin/anaconda/envs/rpi/bin/python
(rpi) arnold#bottie:~/bin/opencv/opencv/build
There is python in /bin/python and /usr/bin/python I found out with vscode. I tried both and both failed.
My questions:
did installation of opencv really succeed?
if so, is it possible to 'connect' the installation to a running version of python, preferably a conda environment?
if not, what is the best way to proceed?
I try this links. install OpenCV 4 for RPI 4 It worked for me using RPi 4B/8GB 64-bit.
Do update first
Install OpenCV
Check getBuildInformation()
After that if not getting . Then install sudo apt
pyhton3-opencv-contrib
No needed to do cmake. And you ready to go.

Python VScode cannot import pyodbc library

I am using VScode to run my python code.
I can pip install all my libraries without problem and also use them.
With the "Pyodbc" library I have a problem.
I can install it normally but when I want to import it I get this error:
Traceback (most recent call last):
File "/Users/marvin/Documents/Python Projects /VSCode/SQL_test.py", line 1, in <module>
import pyodbc
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyodbc.cpython-311-darwin.so, 0x0002): Library not loaded: /usr/local/opt/unixodbc/lib/libodbc.2.dylib
Referenced from: /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyodbc.cpython-311-darwin.so
Reason: tried: '/usr/local/opt/unixodbc/lib/libodbc.2.dylib' (no such file), '/usr/lib/libodbc.2.dylib' (no such file)
Does somebody know this problem and could possibly help me?
Best,
Marvin
Importing the pyodbc library to connect with an azure sql database.

Import cv2 doesn't work despite having installed OpenCV-python

I am a newbie and have been trying to run a python code that uses cv2. I am using the python 3.6.8 terminal.
Please see below for the first part of the code:
import cv2
import numpy as np
import os
import sys
import tensorflow as tf
from sklearn.model_selection import train_test_split
Although I have installed opencv-python, I get a "Module not found" error message as below:
(base) Dhammas-MacBook-Air:python-code-r dhammaandrivini$ python3 traffic.py
Traceback (most recent call last):
File "traffic.py", line 1, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'
I would be most grateful for any help with this, as I really want to finish this project! :)
It is most likely that you have installed the package using pip install opencv-python. This is the correct command but if you have multiple python installations on your device it might lead to issues.
I would suggest you try and use the command python3 -m pip install opencv-python, this command will install opencv for the pip being used by python3, which you seem to be using to run your code.

i installed opencv-python getting import error

import cv2
ImportError Traceback (most recent call
last) in
----> 1 import cv2
~\Anaconda3\lib\site-packages\cv2__init__.py in
3 import sys
4
----> 5 from .cv2 import *
6 from .data import *
7
ImportError: DLL load failed: The specified module could not be found
Looks like you are using Anaconda. If so don't use pip as it can break your environment, use conda.
You can try by
first going to "anaconda-prompt" using windows search and then run the command as below:
conda install -c conda-forge opencv
or any other from https://anaconda.org/conda-forge/opencv.
Maybe you can uninstall and install opencv. This usually happens when you download package at a different file location or the package itself is not installed properly.
I suggest using this:
1.pip install opencv-python
or if you need the full module (cnn, face analysis, shape and etc)
2.pip install opencv-python-contrib

Pyscripter - ImportError: DLL load failed: %1 is not a valid Win32 application

I am new to Pyscripter and found it interesting but getting the below error. lumberjack is an internal framework to work with.
>>> import lumberjack
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Perforce\svasudevan\HPro\lumberjack\__init__.py", line 1, in <module> import analysis
File "C:\Perforce\svasudevan\HPro\lumberjack\analysis.py", line 11, in <module> import scipy.signal
File "C:\Python27\lib\site-packages\scipy\signal\__init__.py", line 227, in <module> from . import sigtools
ImportError: DLL load failed: %1 is not a valid Win32 application.
I am sure that nothing wrong with the code above as I tried with Enthought Canopy and it works fine, since Pyscripter has more options to do with, I am using it but getting the above error.
FYI, all the modules like Numpy, Matplotlib, Scipy and Pyaudio has been imported successfully.
Could you please let me know the pre requisites to be done to correct this error. I think there is some problem with the env variables.
Thanks
Shobith
I'm guessing that the version of Python that PyScripter is running is different than the one you get in EPD/Canopy (Python is compiled C code, so the version matters). There's another question about controlling the version of Python used with PyScripter.
I solved this problem, not exactly like yours but with a similar error, but going to the Run menu, then Python engine, then switching to remote from internal. I had noticed that I could import the module in IDLE but not PyScripter.

Resources