python - 如何在 python 虚拟环境之外使用 Opencv?

标签 python opencv ubuntu-14.04 anaconda

所以我想在 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/

相关文章:

matlab - 验证相机校准仍然有效

python - 如何在 Python 中使用 tcp 套接字发送和接收网络摄像头流?

node.js - 无法在 ubuntu slave 上运行 npm

python - 使用 Python 类型的 TypeVar 进行带绑定(bind)的通用类型返回

c++ - 改进 OpenCV 中的 Grabcut

python - 如何在 Ubuntu 14.04 上安装 pybonjour

linux - Mongo 守护进程不由 service mongod start 运行

python - 如何使用 Python 3.x 将回调及其参数从包装函数传递给装饰器?

python - 如何在python pandas中使用df.loc和if条件删除一行

python - 计算数字中的数字之和,使用/和%时结果不正确