- 之前安裝python版opencv,需要下載whl文件,進行安裝,這是在window環境下的:
- 安裝opencv_python,下載whl包
安裝系統python下的opencv
-
今天發現一個簡單的方法。
Install package python-opencv with following command in terminal (as root user).
$ sudo apt-get install python-opencv
Open Python IDLE (or IPython) and type following codes in Python terminal.
import cv2 as cv
print(cv.__version__)
If the results are printed out without any errors, congratulations !!! You have installed OpenCV-Python successfully.
針對conda環境下env安裝python-opencv
- 發現有些坑
- 首先,我們直接編譯opencv應該就有python的接口:/usr/local/lib/python3.5/dist-packages;發現有
cv2.cpython-35m-x86_64-linux-gnu.so
文件,說的直接拷貝到env下的site-packages,結果報錯
; - 然后我們本身直接
sudo apt-get install python-opencv
安裝的是直接可以使用的; - sudo直接安裝按系統默認的python2.7上:
/usr/lib/python2.7/dist-packages
下面有cv2.x86_64-linux-gnu.so;
rjw@rjw:~$ /usr/bin/python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'2.4.9.1'
-
中間還有錯: Python 3.5 ImportError: dynamic module does not define module export function (PyInit_cv2)
-
參考的方法: Linux下安裝python-opencv
-
最終解決方法:
conda install -c menpo opencv3
:Mac+anaconda+python3.6安裝opencv3
(tensorflow) rjw@rjw:~$ python
Python 3.5.6 |Anaconda, Inc.| (default, Aug 26 2018, 21:41:56)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.2.0'
-
直接
conda install python-opencv
在conda環境下找不到包 -
update2018.11.11;今天遇到個問題:
UnsatisfiableError: The following specifications were found to be in conflict: - opencv3 -> python
- 重新使用:
pip install opencv-python
(maskrcnn_benchmark) rjw@rjw:~/desktop$ pip install opencv-python
Collecting opencv-python
Downloading https://files.pythonhosted.org/packages/d2/cf/1e5774811aa1b656fba8476e98edab2f99a7683c3aaeede057cdc9959c24/opencv_python-3.4.3.18-cp37-cp37m-manylinux1_x86_64.whl (25.0MB)
100% |████████████████████████████████| 25.0MB 72kB/s
Requirement already satisfied: numpy>=1.14.5 in /home/rjw/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages (from opencv-python) (1.15.4)
Installing collected packages: opencv-python
Successfully installed opencv-python-3.4.3.18
- 可以想想,在anaconda下怎么使用自己編譯的opencv,這樣就可以萬能使用!!!
其他錯誤
- 遇到下面問題,使用
conda install -c asmeurer pango
,參考github:Qt fails in GNOME/Fedora 22
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /usr/lib/x86_64-linux-gnu/libpangoft2-1.0.so.0: undefined symbol: hb_font_funcs_set_variation_glyph_func