所以我想在 Ubuntu 14.04 系统上使用 OpenCV 和 Python。 要安装它,我遵循了本教程:
https://www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu/#comment-441399
当我处于教程建议创建的环境中时,一切正常。但是如果我在环境之外尝试,我会收到以下错误:
$ python
Python 2.7.14 |Anaconda, Inc.| (default, Oct 16 2017, 17:29:19)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cv2
>>>
最佳答案
链接教程中的第 8 步向您解释了为什么作者要添加使用虚拟环境的额外步骤:
Step 8:
Install virtualenv and virtualenvwrapper. These two packages allow us to create separate Python environments for each project we are working on. While installing virtualenv and virtualenvwrapper is not a requirement to get OpenCV 3.0 and Python 2.7+ up and running on your Ubuntu system, I highly recommend it and the rest of this tutorial will assume you have them installed!
如果您不想将它包装在虚拟环境中并且在整个系统中只能访问一个版本的 OpenCV,那么基本上只需跳过这一步。
然后当您到达第 11 步时,您可以忽略关于必须进入 CV 虚拟环境的建议,因为您应该可以从任何地方访问它。忽略此建议:
However, our cv virtual environment is located in our home directory — thus to use OpenCV within our cv environment, we first need to sym-link OpenCV into the site-packages directory of the cv virtual environment:
话虽这么说,您实际上可以按照 OpenCV 教程进行操作,而不会将其安装到虚拟环境中。您可以访问该教程 here
关于python - 如何在 python 虚拟环境之外使用 Opencv?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47451166/