Can't import openCV in anaconda Python 3.10 - python

I installed openCV onto Python 3.10 and it's erroring in the import stage.
Any ideas on what to try for this?
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\ProgramData\Anaconda3\envs\myenv\lib\site-packages\cv2\__init__.py", line 181, in <module>
bootstrap()
File "C:\ProgramData\Anaconda3\envs\myenv\lib\site-packages\cv2\__init__.py", line 153, in bootstrap
native_module = importlib.import_module("cv2")
File "C:\ProgramData\Anaconda3\envs\myenv\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: DLL load failed while importing cv2: The specified module could not be found.
>>> ^Z
(myenv) C:\Users\Eli Rogers>python -V
Python 3.10.6

Here you are getting error because the interpreter has already started and when you have retype the python it is interpreting it as a variable so .
you can check out this :
NameError: name 'python' is not defined
where the same problem has discussed

Related

ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation

I was just finished compiling opencv2 using visual studio and CMake, i finished building the library and was about to test it in my cmd prompt and i got this error.
Here is a the error:
site-packages\\win32', 'C:\\Users\\Talla\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\win32\\lib', 'C:\\Users\\Talla\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\Pythonwin']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Talla\AppData\Local\Programs\Python\Python39\lib\site-packages\cv2\__init__.py", line 180, in <module>
bootstrap()
File "C:\Users\Talla\AppData\Local\Programs\Python\Python39\lib\site-packages\cv2\__init__.py", line 152, in bootstrap
native_module = importlib.import_module("cv2")
File "C:\Users\Talla\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\Talla\AppData\Local\Programs\Python\Python39\lib\site-packages\cv2\__init__.py", line 180, in <module>
bootstrap()
File "C:\Users\Talla\AppData\Local\Programs\Python\Python39\lib\site-packages\cv2\__init__.py", line 75, in bootstrap
raise ImportError('ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.')
ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.
>>>
Any suggestions on how to solve this?
Found a solution after some digging.
This fixed it:
pip3 install opencv-python --upgrade --force-reinstall # [--user]

Why does this error appear when I try to run Spyder on Anaconda?

I get an error whenever I try to run Spyder on Anaconda. I reinstalled more than 5 times and tried to fix Windows' variables path but it does not work at all.
Could anyone help me fix this problem?
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\Scripts\spyder-script.py", line 6, in
from spyder.app.start import main
File "C:\ProgramData\Anaconda3\lib\site-
packages\spyder\app\start.py", line 22, in
import zmq
File "C:\Users\USER\AppData\Roaming\Python\Python38\site-
packages\zmq\__init__.py", line 62, in
from zmq import backend
File "C:\Users\USER\AppData\Roaming\Python\Python38\site-
packages\zmq\backend\__init__.py", line 32, in
raise original_error from None
File "C:\Users\USER\AppData\Roaming\Python\Python38\site-
packages\zmq\backend\__init__.py", line 27, in
_ns = select_backend(first)
File "C:\Users\USER\AppData\Roaming\Python\Python38\site-
packages\zmq\backend\select.py", line 32, in select_backend
mod = import_module(name)
"C:\ProgramData\Anaconda3\lib\importlib\__init__.py", line 127, in
import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\USER\AppData\Roaming\Python\Python38\site-
packages\zmq\backend\cython\__init__.py", line 6, in
from . import (
ImportError: cannot import name 'constants' from partially
initialized module 'zmq.backend.cython' (most likely due to a
circular import)
(C:\Users\USER\AppData\Roaming\Python\Python38\site-
packages\zmq\backend\cython\__init__.py)
(Spyder maintainer here) This happens because you installed some package using pip into this directory:
C:\Users\USER\AppData\Roaming\Python
So the solution is to remove that directory completely and Spyder will start again without problems.

Cannot run jupyter everywhere (terminal, anaconda distributer) Mac os 10.12.6

I got a problem with running jupyter in the terminal.
What terminal says after running
maxim#MacBook-Pro-Maxim  ~  jupyter notebook
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/bin/jupyter-notebook", line 5, in <module>
from notebook.notebookapp import main
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/notebook/notebookapp.py", line 49, in <module>
from zmq.eventloop import ioloop
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/zmq/__init__.py", line 62, in <module>
from zmq import backend
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/zmq/backend/__init__.py", line 32, in <module>
raise original_error from None
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/zmq/backend/__init__.py", line 27, in <module>
_ns = select_backend(first)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/zmq/backend/select.py", line 32, in select_backend
mod = import_module(name)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/zmq/backend/cython/__init__.py", line 6, in <module>
from . import (
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/zmq/backend/cython/constants.cpython-39-darwin.so, 2): Symbol not found: ____chkstk_darwin
Referenced from: /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/zmq/backend/cython/../../.dylibs/libsodium.23.dylib
Expected in: /usr/lib/libSystem.B.dylib
in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/zmq/backend/cython/../../.dylibs/libsodium.23.dylib
I was trying to use Anaconda and got the same issue
For me, it seems to be something wrong with path...
Please help me to resolve it or give a hint of what to do
I'm seeing the exact same issue - seems the zmq package has a /cython/ in it with incompatible references. Is it not using cython from the site-packages? I've tried reinstalling cython, pyzmq, and all the jupyter modules with no joy yet.
EDIT - I downgraded pyzmq to 20.0.0 and it worked fine.
pip install pyzmq==20.0.0
I believe the issue is in pyzmq's cython packaging - and should be raised as a bug to them.

"This package should not be accessible on Python 3" error

I installed phenix (phenix-installer-1.17.1-3660-intel-linux-2.6-x86_64-centos6) on my CentOS 7 system according the installation guide (https://www.phenix-online.org/documentation/install-setup-run.html). The original python version (/usr/bin/python) in my system is 2.7.5, but I installed anaconda3, so the output of "which python" command is "~/software/build/anaconda3/bin/python".
I tried to study the p9-sad tutorial and run the command "phenix.run_example p9-sad", but it gave the following error information:
Examples to be run: p9-sad
Running PHENIX example: p9-sad Fri Jan 17 15:04:44 CST 2020
Working directory: /home/sunyp/Documents/tutorial/PHENIX/p9-sad
Starting run now ... please wait a moment
Error processing line 1 of /home/sunyp/software/build/anaconda3/lib/python3.7/site-packages/google_auth-1.7.1-py3.6-nspkg.pth:
Fatal Python error: initsite: Failed to import the site module
Traceback (most recent call last):
File "/home/sunyp/software/build/anaconda3/lib/python3.7/site.py", line 168, in addpackage
exec(line)
File "<string>", line 1, in <module>
File "/home/sunyp/software/build/anaconda3/lib/python3.7/importlib/util.py", line 14, in <module>
from contextlib import contextmanager
File "/home/sunyp/software/build/anaconda3/lib/python3.7/contextlib.py", line 5, in <module>
from collections import deque
File "/home/sunyp/software/build/anaconda3/lib/python3.7/collections/__init__.py", line 27, in <module>
from reprlib import recursive_repr as _recursive_repr
File "/home/sunyp/software/Phenix/phenix-1.17.1-install/phenix-1.17.1-3660/conda_base/lib/python2.7/site-packages/reprlib/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/sunyp/software/Phenix/phenix-1.17.1-install/phenix-1.17.1-3660/build/../conda_base/lib/python2.7/site-packages/site.py", line 73, in <module>
__boot()
File "/home/sunyp/software/Phenix/phenix-1.17.1-install/phenix-1.17.1-3660/build/../conda_base/lib/python2.7/site-packages/site.py", line 22, in __boot
loader.load_module('site')
File "/home/sunyp/software/build/anaconda3/lib/python3.7/site.py", line 570, in <module>
main()
File "/home/sunyp/software/build/anaconda3/lib/python3.7/site.py", line 557, in main
known_paths = addsitepackages(known_paths)
File "/home/sunyp/software/build/anaconda3/lib/python3.7/site.py", line 349, in addsitepackages
addsitedir(sitedir, known_paths)
File "/home/sunyp/software/build/anaconda3/lib/python3.7/site.py", line 207, in addsitedir
addpackage(sitedir, name, known_paths)
File "/home/sunyp/software/build/anaconda3/lib/python3.7/site.py", line 178, in addpackage
import traceback
File "/home/sunyp/software/build/anaconda3/lib/python3.7/traceback.py", line 3, in <module>
import collections
File "/home/sunyp/software/build/anaconda3/lib/python3.7/collections/__init__.py", line 27, in <module>
from reprlib import recursive_repr as _recursive_repr
File "/home/sunyp/software/Phenix/phenix-1.17.1-install/phenix-1.17.1-3660/conda_base/lib/python2.7/site-packages/reprlib/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Does it mean that phenix requires python2 rather python3, but there is python3 in my system, so the error came out? And how to solve the problem? Thank you in advance.
Regards,
Yeping Sun
Solely based on /home/sunyp/software/Phenix/phenix-1.17.1-install/phenix-1.17.1-3660/conda_base/lib/python2.7/site-packages/reprlib/__init__.py Phenix contains a Python 2.7 environment.
You could maybe try running your code with /home/sunyp/software/Phenix/phenix-1.17.1-install/phenix-1.17.1-3660/conda_base/bin/python or something to use that Python interpreter, but it's hard to tell since Phenix source is not openly available.
Your environment probably contains path to python2.7.5
Check your PYTHONPATH
This doesn't work with Python 3 for obvious reasons. To remove it:
unset PYTHONPATH

Issues Installing SimpleElastix on Ubuntu for Python

I am trying to install SimpleElastix/SimpleITK on an Ubuntu computer for either Python2 or 3, whichever we can get to work. Using pip install doesn't work as various methods don't import then (e.g. no "GetDefaultParameterMethod" exists). I tried following the instructions on their website (https://simpleelastix.readthedocs.io/GettingStarted.html#compiling-on-linux), but even though no errors are thrown throughout the process, I am still unable to import.
For Python3, the typical "No module" error pops up, but for Python2 I get the following:
>>> import SimpleITK as sitk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/SimpleITK-1.0.1rc1.dev345+g9dfa8-py2.7-linux-x86_64.egg/SimpleITK/__init__.py", line 1, in <module>
from .SimpleITK import *
File "/usr/local/lib/python2.7/dist-packages/SimpleITK-1.0.1rc1.dev345+g9dfa8-py2.7-linux-x86_64.egg/SimpleITK/SimpleITK.py", line 17, in <module>
_SimpleITK = swig_import_helper()
File "/usr/local/lib/python2.7/dist-packages/SimpleITK-1.0.1rc1.dev345+g9dfa8-py2.7-linux-x86_64.egg/SimpleITK/SimpleITK.py", line 16, in swig_import_helper
return importlib.import_module('_SimpleITK')
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named _SimpleITK
Any help would be greatly appreciated :)

Categories