Win10+Anaconda3环境下的OpenCV4.0-Python安装教程
python基础教程电子书百度云在Ubuntu16.04环境下,进⼊Anaconda虚拟环境,输⼊
pip install opencv-python -i pypi.tuna.tsinghua.edu/simple/
可以直接安装OpenCV 4.0了,⼀⾏代码搞定,美滋滋。
Win10+Anaconda3环境下的OpenCV4.0-Python安装教程
在OpenCV 3.0发布三年半之后,OpenCV 4.0终于发布了。我看了⼀下⽹上的教程都是利⽤Visual Studio对OpenCV源码进⾏编译的办法来安装的,繁琐不说,还容易出错。我尝试了⼀下⽤编译好的版本结合Anaconda3进⾏OpenCV4.0安装,完美⽀持Python2.7版本,对Python3,⽬前还只能在...\site-packages\opencv\build\python这个路径下运⾏,还请各路⼤神多多指点。
创建虚拟环境
⾸先安装Anaconda3,安装步骤不再赘述,可以参考我前⾯的博客
安装完之后,打开命令⾏,输⼊以下命令,创建⼀个虚拟环境,在⾥⾯乱搞是不会破坏外⾯配置好的环境的。环境的名字可以随便取,我取的是opencv40,python版本⽤3.5就⾏。
conda create -n opencv40 python=3.5
⽤conda env list来查看已创建的所有环境,⽤activate opencv40来激活环境,输⼊conda install numpy matplotlib安装必要的package。如果安装速度慢,可以。
下载OpenCV 4.0.0-alpha
OpenCV的下载⽹址,在这⾥可以看到所有的发⾏版本。
vba inputbox输入密文最新的版本是OpenCV4.0,还有两个版本是alpha和beta。我下载了4.0.0和4.0.0-alpha两个版本。
点击4.0.0-alpha,选择红框的⽂件下载。
如果连接不稳定,可以⽤我的百度云链接。
4.0.0
4.0.0-alpha
integer占几个字节下载完之后,双击打开exe⽂件,将其解压到D:\Program Files\Anaconda3\envs\OpenCV40\Lib\site-packages,这是我的Anaconda3的虚拟环境opencv40下的Python的package存放路径。
如果你之前解压的是4.0.0-alpha,则进⼊...\site-packages\opencv\python\2.7\x64,将cv2.pyd复制到...\Anaconda3\envs\OpenCV40\Lib\site-packages中。
在命令⾏(环境激活状态下)进⼊python,如下图可见安装成功。
如果你之前解压的是4.0.0,则命令⾏进⼊...\site-packages\opencv\python\,执⾏python setup.py install,如下图。
然后不知为何报错了
Traceback (most recent call last):
File "setup.py", line 57, in <module>
main()
国产舍曲林效果太差File "setup.py", line 52, in main
'Topic :: Software Development :: Libraries',哔哩哔哩轮播是什么意思
File "D:\Program Files\Anaconda3\envs\opencv40\lib\distutils\core.py", line 151, in setup
dist.run_commands()
File "D:\Program Files\Anaconda3\envs\opencv40\lib\distutils\dist.py", line 953, in run_commands
self.run_command(cmd)
File "D:\Program Files\Anaconda3\envs\opencv40\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "D:\Program Files\Anaconda3\envs\opencv40\lib\site-packages\setuptools\command\install.py", line 67, in run
self.do_egg_install()
File "D:\Program Files\Anaconda3\envs\opencv40\lib\site-packages\setuptools\command\install.py", line 117, in do_egg_install
cmd.run()
File "D:\Program Files\Anaconda3\envs\opencv40\lib\site-packages\setuptools\command\easy_install.py", line 411, in run
self.easy_install(spec, _deps)
File "D:\Program Files\Anaconda3\envs\opencv40\lib\site-packages\setuptools\command\easy_install.py", line 642, in easy_install
with self._tmpdir() as tmpdir:
File "D:\Program Files\Anaconda3\envs\opencv40\lib\contextlib.py", line 17, in __enter__
xt()
File "D:\Program Files\Anaconda3\envs\opencv40\lib\site-packages\setuptools\command\easy_install.py", line 631, in _tmpdir
tmpdir = tempfile.mkdtemp(prefix=six.u("easy_install-"))
File "D:\Program Files\Anaconda3\envs\opencv40\lib\tempfile.py", line 337, in mkdtemp
file = _os.path.join(dir, prefix + name + suffix)
File "D:\Program Files\Anaconda3\envs\opencv40\lib\ntpath.py", line 85, in join
result_path = result_path + p_path
UnicodeDecodeError: 'ascii' codec can't decode byte 0xbb in position 7: ordinal not in range(128)
在python3中导⼊cv2会爆出⼀个这样的错误,
['D:\\Program Files\\Anaconda3\\envs\\OpenCV\\lib\\site-packages\\opencv-4.0.\\cv2\\../../python/cv2/python-3.5', '', 'D:\\Program Files\\Anacon da3\\envs\\OpenCV\\python35.zip', 'D:\\Program Files\\Anaconda3\\envs\\OpenCV\\DLLs', 'D:\\Program Files\\Anaconda3\\envs\\OpenCV\\lib', 'D:\\Program  Files\\Anaconda3\\envs\\OpenCV', 'D:\\Program Files\\Anaconda3\\envs\\OpenCV\\lib\\site-packages', 'D:\\Program Files\\Anaconda3\\envs\\OpenCV\\lib\\s ite-packages\\opencv-4.0.', 'D:\\Program Files\\Anaconda3\\envs\\OpenCV\\Lib\\site-packages\\opencv']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\Program Files\Anaconda3\envs\OpenCV\lib\site-packages\opencv-4.0.\cv2\__init__.py", line 89, in <module>
bootstrap()
File "D:\Program Files\Anaconda3\envs\OpenCV\lib\site-packages\opencv-4.0.\cv2\__init__.py", line 79, in bootstrap
import cv2
File "D:\Program Files\Anaconda3\envs\OpenCV\lib\site-packages\opencv-4.0.\cv2\__init__.py", line 89, in <module>
bootstrap()
File "D:\Program Files\Anaconda3\envs\OpenCV\lib\site-packages\opencv-4.0.\cv2\__init__.py", line 23, in bootstrapbasicdatasource
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.

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。