对于无法在OSX中的python中导入cv2感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍python无法导入包,并为您提供关于Anaconda:即使已安装opencv,也无法导入cv2(如何
对于无法在OSX中的python中导入cv2感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍python无法导入包,并为您提供关于Anaconda:即使已安装opencv,也无法导入cv2(如何为python3安装opencv3)、OpenCV的Python OSX、python – 无法在openERP中导入自定义模块、python – 无法在脚本中导入导入日期时间的有用信息。
本文目录一览:- 无法在OSX中的python中导入cv2(python无法导入包)
- Anaconda:即使已安装opencv,也无法导入cv2(如何为python3安装opencv3)
- OpenCV的Python OSX
- python – 无法在openERP中导入自定义模块
- python – 无法在脚本中导入导入日期时间
无法在OSX中的python中导入cv2(python无法导入包)
我已经在Mac中安装了OpenCV 3.1,也通过安装了cv2 pip install cv2
。
vinllen@ $ pip install cv2You are using pip version 7.1.0, however version 7.1.2 is available.You should consider upgrading via the ''pip install --upgrade pip'' command.Requirement already satisfied (use --upgrade to upgrade): cv2 in /usr/local/lib/python2.7/site-packages
但是它看起来像cv2
并且cv
不能使用:
Python 2.7.10 (default, Jul 13 2015, 12:05:58)[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwinType "help", "copyright", "credits" or "license" for more information.>>> import cv2Traceback (most recent call last): File "<stdin>", line 1, in <module>ImportError: No module named cv2>>> import cvTraceback (most recent call last): File "<stdin>", line 1, in <module>ImportError: No module named cv
我已经尝试了几乎所有在线解决方案列表,但是无法正常工作。
答案1
小编典典我不知道pip install cv2
实际安装的是什么…但是肯定 不是 OpenCV。 pip installcv2
实际上安装了this,这是一些 博客分发实用程序
,不确定它是什么,但 不是 OpenCV。
要正确安装OpenCV,请检查注释中添加的任何链接@ udit043,或参阅以下任何教程:
在此处找到有关如何在OS
X上安装OpenCV的教程:http :
//www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2-7-on-
osx/
您实际上需要从源代码编译OpenCV并激活python绑定,这需要一段时间。
另一种选择是使用它brew
来获取OpenCV,但不一定能为您提供最新版本或完全优化的版本:
https://web.archive.org/web/20171218032016/http://www.mobileway.net/2015/02/14/install-
opencv-for-python-on-mac-
os-x/
Anaconda:即使已安装opencv,也无法导入cv2(如何为python3安装opencv3)
我安装了Anaconda(版本:conda 4.2.9,python3),并import cv2
在遇到以下错误时尝试这样做:
ImportError: No module named ''cv2''
随着conda search cv2
我得到这个:
opencv 2.4.2 np15py26_0 defaults 2.4.2 np15py27_0 defaults 2.4.2 np16py26_0 defaults 2.4.2 np16py27_0 defaults 2.4.2 np17py26_0 defaults 2.4.2 np17py27_0 defaults 2.4.2 np15py26_1 defaults 2.4.2 np15py27_1 defaults 2.4.2 np16py26_1 defaults 2.4.2 np16py27_1 defaults 2.4.2 np17py26_1 defaults 2.4.2 np17py27_1 defaults 2.4.6 np16py26_0 defaults 2.4.6 np16py27_0 defaults 2.4.6 np17py26_0 defaults 2.4.6 np17py27_0 defaults 2.4.6 np18py26_0 defaults 2.4.6 np18py27_0 defaults 2.4.9 np18py27_0 defaults 2.4.10 np19py26_0 defaults 2.4.10 np19py27_0 defaults 2.4.10 np110py27_1 defaults 2.4.10 np19py26_1 defaults 2.4.10 np19py27_1 defaults
我需要做些什么才能导入cv2模块?
我正在使用Ubuntu 16.04。
答案1
小编典典opencv与python 3不兼容。我必须为python
3安装opencv3。在我们如何在anaconda上安装opencv的明显答案?解释了如何为蟒蛇安装opencv(3):
运行以下命令:
conda install -c https://conda.binstar.org/menpo opencv
我意识到opencv3现在也可用,运行以下命令:
conda install -c https://conda.binstar.org/menpo opencv3
编辑于2016年8月18日: 您可以通过以下方式永久添加“ menpo”频道:
conda config --add channels menpo
然后可以通过以下方式安装opencv:
conda install opencv (or opencv3)
2017年8月14日编辑: “ Clinicalgraphics ”频道为最近的python3提供了相对较新的vtk版本
conda install -c clinicalgraphics vtk
于2020年4月16日进行编辑(基于@AMC的评论): 可以通过以下方式安装OpenCV
conda-forge
(详细信息请参见此处)
conda install -c conda-forge opencv
OpenCV的Python OSX
(第1步)
我正在尝试使用MacPorts安装http://opencv.willowgarage.com/wiki/Mac_OS_X_OpenCV_Port从Mac上的python中运行python来运行openCV
,并尝试遵循Petite Geek的指南:
sudo port -v install opencv +python26
它运行约10分钟,没有错误。
(第2步)
我下载了ctypes-opencv源代码和演示文件。我导航到src
目录并运行:
sudo python setup.py install
我看到几乎所有形式的50行代码:copying ... -> ...
,对我来说看起来不错。这里没有错误。
(第3步)
我添加export DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib
到我的末尾~/.profile
。
(步骤4)
我打开一个新终端以测试我的安装。从我的主文件夹中:
$ pythonPython 2.6.2 (r262:71600, Apr 16 2009, 09:17:39) [GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwinType "help", "copyright", "credits" or "license" for more information.>>> import cvTraceback (most recent call last): File "<stdin>", line 1, in <module>ImportError: No module named cv>>>
不起作用。
我在某处读到opencv使用OSX的默认版本的python安装python绑定,并且我可能正在运行非默认版本,但这对我来说不是可操作的信息。
答案1
小编典典我在Mac上使用Python挣扎了一段时间。这是我终于(而且很容易!)安装它的方式。删除所有您已经拥有的Python。它们可能位于/Library/Frameworks/Python.Framework和/
opt / local / var / macports / software / py26 *
首先使用Macports下载Python。
sudo port install python27
然后确保您的系统正在使用此版本:
sudo port select --set python python27
接下来安装numpy:
sudo port install py27-numpy
现在安装opencv:
sudo port install opencv +python27
现在,使用以下命令编辑〜/ .bash_profile:
sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit ~/.bash_profile
要么
open -t ~/.bash_profile
并添加以下行:
export PYTHONPATH=/opt/local/var/macports/software/opencv/2.2.0_0+python27/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages:$PYTHONPATH
或隐藏您的cv.so文件版本的位置。
现在重新启动终端,然后尝试:
%python>>>import cv
我正在将Netbeans用于opencv和python,它的工作原理非常好。祝好运。
python – 无法在openERP中导入自定义模块
这是__init__py
import os os.environ['TZ'] = 'UTC' # Set the timezone... import time # ... *then* import time. del os del time # The hard-coded super-user id (a.k.a. administrator,or root user). SUPERUSER_ID = 1 import addons import cli import conf import loglevels import modules import netsvc import osv import pooler import release import report import service import sql_db import tools import workflow import sim # backward compatilbility # Todo: This is for the web addons,can be removed later. wsgi = service wsgi.register_wsgi_handler = wsgi.wsgi_server.register_wsgi_handler # Is the server running in multi-process mode (e.g. behind Gunicorn). # If this is True,the processes have to communicate some events,# e.g. database update or cache invalidation. Each process has also # its own copy of the data structure and we don't need to care about # locks between threads. multi_process = False # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
这是__openerp__.py
{ 'name': 'Student information Management','version': '0.1','category': 'Tools','description': """This module is for the Student information Management.""",'author': 'Mir Nauman Tahir','website': 'http://mirnauman.wordpress.com/','depends': ['base'],'init_xml': [],'update_xml': ['sim_view.xml'],'demo_xml': [],'installable': True,'active': True,}
这是sim_view.xml
<?xml version="1.0"?> <openerp> <data> <!-- ============== student================= --> <!-- 1st part of the sim_view start--> <record model="ir.ui.view" id="student_form"> <field name="name">Student</field> <field name="model">sim.student</field> <field name="type">form</field> <field name="arch" type="xml"> <form string="Student" version="7.0"> <field name="name"/> <field name="student_name"/> <field name="father_name"/> <field name="gender"/> <field name="contact_no"/> </form> </field> </record> <!-- 1st part of the sim_view end--> <!--2nd part of the sim_view start--> <record model="ir.ui.view" id="student_tree"> <field name="name">Student</field> <field name="model">sim.student</field> <field name="type">tree</field> <field name="arch" type="xml"> <tree string="Student"> <field name="name"/> <field name="student_name"/> <field name="father_name"/> <field name="gender"/> <field name="contact_no"/> </tree> </field> </record> <!--2nd part of the sim_view end--> <!-- 3rd part of the sim_view start--> <record model="ir.actions.act_window" id="action_student"> <field name="name">Student</field> <field name="res_model">sim.student</field> <field name="view_type">form</field> <field name="view_mode">tree,form</field> </record> <!--3rd part of the sim_view end--> <!--4th part of the sim_view start--> <menuitem name="SIM/Student/StudentInfo" id="menu_sim_student" action="action_student"/> <!--4th part of the sim_view end--> </data> </openerp>
这个sim.py
from openerp.osv import fields class student(osv.osv): _name = "sim.student" _description = "This table is for keeping personal data of student" _columns = { 'name': fields.char('Registration Number',size=256,required=True),'student_name': fields.char('Student Name','father_name': fields.char('Father Name',size=256),'gender':fields.selection([('male','Male'),('female','Female')],'Gender'),'contact_no':fields.char('Contact Number',size=256) } student()
我在openerp中看不到我的模块.我怎样才能解决这个问题?
解决方法
__openerp__.py File { 'name': 'Student information Management','data': ['sim_view.xml'],'demo': [],'auto_install': False,'application': True,} __init__.py File import sim sim.py File from openerp.osv import fields,osv class student(osv.osv): _name = "sim.student" _description = "This table is for keeping personal data of student" _columns = { 'name': fields.char('Registration Number',size=256) } student() sim_view.xml File <?xml version="1.0"?> <openerp> <data> <!-- ============== student================= --> <!-- 1st part of the sim_view start--> <record model="ir.ui.view" id="student_form"> <field name="name">Student</field> <field name="model">sim.student</field> <field name="type">form</field> <field name="arch" type="xml"> <form string="Student" version="7.0"> <group> <field name="name"/> <field name="student_name"/> <field name="father_name"/> <field name="gender"/> <field name="contact_no"/> </group> </form> </field> </record> <!-- 1st part of the sim_view end--> <!--2nd part of the sim_view start--> <record model="ir.ui.view" id="student_tree"> <field name="name">Student</field> <field name="model">sim.student</field> <field name="type">tree</field> <field name="arch" type="xml"> <tree string="Student"> <field name="name"/> <field name="student_name"/> <field name="father_name"/> <field name="gender"/> <field name="contact_no"/> </tree> </field> </record> <!--2nd part of the sim_view end--> <!-- 3rd part of the sim_view start--> <record model="ir.actions.act_window" id="action_student"> <field name="name">Student</field> <field name="res_model">sim.student</field> <field name="view_type">form</field> <field name="view_mode">tree,form</field> </record> <!--3rd part of the sim_view end--> <!--4th part of the sim_view start--> <menuitem name="SIM/Student/StudentInfo" id="menu_sim_student" action="action_student"/> <!--4th part of the sim_view end--> </data> </openerp>
更新完所有文件后,重新启动服务器,更新模块列表并找到您的
设置>中的模块模块>已安装的模块 – 从那里卸下安装并在那里写下你的模块名称(即sim).
希望这肯定会奏效.
python – 无法在脚本中导入导入日期时间
我无法从python脚本导入日期时间,但我可以从终端命令行.
1)import datetime 2)From datetime import datetime month = datetime.datetime.Now().strftime("%B") print month
这些代码行在逐个输入命令行时起作用
有任何想法吗?
我在Mac上运行2.7
解决方法
>您将文件命名为datetime.py以进行测试
>然后你在里面写了导入日期时间,因为这是你想要尝试的模块
运行该文件时会发生什么,是:
> Python首先在本地目录中查找名为datetime的模块
>由于Python只找到你的原始文件,它会生成一个名为datetime.pyc的空模块文件,因为它希望你在它上构建它
幸运的是,StackOverflow上的好人让你意识到这个命名错误,并且你将datetime.py文件重命名为其他东西.但令人困惑的是,你仍然会得到错误,而且挫折感会慢慢增加……
解:
>始终确保您的文件名不等于您要导入的任何python模块
>如果您仍然忘记,请确保删除或重命名本地.py脚本和本地.pyc文件.这应该可以解决您的问题.
总结
以上是小编为你收集整理的python – 无法在脚本中导入导入日期时间全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
我们今天的关于无法在OSX中的python中导入cv2和python无法导入包的分享已经告一段落,感谢您的关注,如果您想了解更多关于Anaconda:即使已安装opencv,也无法导入cv2(如何为python3安装opencv3)、OpenCV的Python OSX、python – 无法在openERP中导入自定义模块、python – 无法在脚本中导入导入日期时间的相关信息,请在本站查询。
本文标签: