I'm currently working on a project with anaconda. I was able to install opencv-python with the regular pip3 install (not anacondas version). When I import cv2, its successful.
Python 3.6.9 (default, Oct 8 2020, 12:12:24)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>>
If I copy that package into my anaconda path, and run python with anaconda, import cv2 I get the following error:
Python 3.7.3 (default, Mar 27 2019, 22:11:17)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'
Is there a way to get around this without using the Anacondas pip install? I don't have internet on the machine I'm working on. I've done this method with other packages and it has worked fine, not with opencv.
Related
When i use python in terminal ;
pi#raspberrypi:~ $ python
Python 3.7.3 (default, Dec 20 2019, 18:57:59)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
2020-07-26 12:52:03.075590: E tensorflow/core/platform/hadoop/hadoop_file_system.cc:132] HadoopFileSystem load error: libhdfs.so: cannot open shared object file: No such file or directory
>>>
But i tried run my py file
pi#raspberrypi:~ $ sudo python /home/pi/tfdeneme.py
pygame 1.9.4.post1
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "/home/pi/tfdeneme.py", line 17, in <module>
import tensorflow
ModuleNotFoundError: No module named 'tensorflow'
Im using tensorflow 2.2.0 on my windows machine, on raspberry pi tensorflow version =
pi#raspberrypi:~ $ python
Python 3.7.3 (default, Dec 20 2019, 18:57:59)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2020-07-26 12:53:49.504578: E tensorflow/core/platform/hadoop/hadoop_file_system.cc:132] HadoopFileSystem load error: libhdfs.so: cannot open shared object file: No such file or directory
>>> tf.__version__
'1.14.0'
Whay should i do to run my py file ?
I was having issues with TF 2.2.0 with python 3.7 and hence downgraded to python 3.6 and now it seems to be working. Please note i am on a Mac though
I've successfully installed OpenCV, but when I try to import it in Python, I get the errors below.
In Python 2.7, I'm getting this
[imukunya#li165-244 site-packages]$ python
Python 2.7.5 (default, Oct 30 2018, 23:45:53)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: numpy.core.multiarray failed to import
In Python 3.6, I'm getting this error
[imukunya#li165-244 site-packages]$ python3.6
Python 3.6.5 (default, Apr 10 2018, 17:08:37)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define module export function (PyInit_cv2)
I've already tried installing NumPy using $~python3 -m pip install numpy -I
Please try to execute the below command. Then please verify whether your code is working.
python -m pip install opencv-contrib-python
I have a django project that I want to use gdal in. I have installed all the dependencies and it works fine if I do:
$ python3.6
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from osgeo import gdal
>>> gdal
<module 'osgeo.gdal' from '/usr/lib/python3/dist-packages/osgeo/gdal.py'>
but when I do:
$python manage.py shell
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from osgeo import gdal
Traceback (most recent call last):
File "<console>", line 1, in <module>
ModuleNotFoundError: No module named 'osgeo'
It appears both are using the same python so I am not sure what the problem is. Could it be a path problem?
As Jonah Bishop suggested, I was able to solve the problem by running:
python3 manage.py shell
I have installed opencv using apt-get. I got opencv2 with the following version and it works fine:
rover#rover_pi:/usr/lib/arm-linux-gnueabihf $ python2.7
Python 2.7.13 (default, Nov 24 2017, 17:33:09)
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'2.4.9.1'
Then I wanted to install opencv on a conda environment using pip. I got the following version
(olfatf)rover#rover_pi:/usr/lib/arm-linux-gnueabihf $ pip list | grep opencv
opencv-python 3.4.0.14
However, I get the following error when I import the module:
(olfatf)rover#rover_pi:/usr/lib/arm-linux-gnueabihf $ python
Python 3.4.3 |Continuum Analytics, Inc.| (default, Aug 21 2015, 00:53:08)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/pi/.conda/envs/olfatf/lib/python3.4/site-packages/cv2/__init__.py", line 3, in <module>
from .cv2 import *
ImportError: libavformat.so.56: cannot open shared object file: No such file or directory
I checked the install libavcodec library and I get the version 57.
(olfatf)rover#rover_pi:/usr/lib/arm-linux-gnueabihf $ ls | grep libavformat
libavformat.a
libavformat.so
libavformat.so.57
libavformat.so.57.56.101
So I want to know why a later version of opencv requires an older version of libavcodec. Also, how can I installed both libavcodec56 and libavcodec57 on my machine ?
I use a raspberry pi with Raspbian Strech
Its not that opencv requires it, Its that whoever compiled the binary of opencv you are using compiled it against libavcodec56. Easiest fix is to compile it yourself.
Also, how can I installed both libavcodec56 and libavcodec57 on my machine ?
Don't. just compile and link against the same version.
I successfully installed nltk and works fine. I have to run a file where nltk was imported and tensorflow too ,hence, i have to activate tensorflow.
When I activate tensorflow the .py file i want to run gives an error. I have read some solution but they didn't help.
HP-250-G5-Notebook-PC:~$ python
Python 3.6.3 |Anaconda custom (64-bit)| (default, Oct 13 2017, 12:02:49)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
>>>
this works fine but this does not
(tensorflow)HP-250-G5-Notebook-PC:~/AIG2018/Chatbot$ python
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
What is that I am doing worng?
ImportError: No module named 'nltk'
You're using two different versions of python, and you probably installed nltk in your root environment, but not your virtual environment. When you "activate" the environment called tensorflow, you are using a different virtual environment, in which you haven't installed nltk. Try activating tensorflow, then using pip install nltk, then starting python. Because you seem to be using anaconda, this would probably look like this:
# Do these first 2 steps in your terminal:
source activate tensorflow
# you're now in the virtual environment called tensorflow
pip install nltk
# you now have nltk in that virtual environment
# Now, you can start python
python
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
And you shouldn't have that error
If you look closely at your messages you will see that the successful import of nltk is on Python 3.6.3 and the failed import is on Python 3.5.2.
This indicates that you have two Python installations of different versions, and nltk is installed in one but not in the other.