无法在Sublime Text中使用Open CV

时间:2018-11-17 14:04:16

标签: python opencv

我无法在Sublime文本中使用OpenCv。每当我尝试构建脚本时,都会引发此错误-

File "C:\Users\ATHARVA\Desktop\Python\circle.py", line 1, in <module>
    import numpy as np

  File "C:\Program Files\Python\lib\site-packages\numpy\__init__.py", line 158, in <module>
    from . import add_newdocs

  File "C:\Program Files\Python\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc

  File "C:\Program Files\Python\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
    from .type_check import *

  File "C:\Program Files\Python\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx

  File "C:\Program Files\Python\lib\site-packages\numpy\core\__init__.py", line 74, in <module>
    from numpy.testing import _numpy_tester

  File "C:\Program Files\Python\lib\site-packages\numpy\testing\__init__.py", line 12, in <module>
    from . import decorators as dec

  File "C:\Program Files\Python\lib\site-packages\numpy\testing\decorators.py", line 6, in <module>
    from .nose_tools.decorators import *

  File "C:\Program Files\Python\lib\site-packages\numpy\testing\nose_tools\decorators.py", line 20, in <module>

    from .utils import SkipTest, assert_warns

  File "C:\Program Files\Python\lib\site-packages\numpy\testing\nose_tools\utils.py", line 15, in <module>
    from tempfile import mkdtemp, mkstemp

  File "C:\Program Files\Python\lib\tempfile.py", line 45, in <module>
    from random import Random as _Random

ImportError: cannot import name 'Random'
[Finished in 0.2s with exit code 1]

我无法理解为什么会出现此错误。有人可以指出问题所在吗?

编辑:-问题已解决。

1 个答案:

答案 0 :(得分:0)

您可能已经创建了一个名为Random.py / random.py的文件,找到并删除它可以解决问题。

  

无法在Sublime Text中导入Ope CV

您也没有导入cv2(OpenCV)。确定您已经安装了OpenCV。 如果尚未安装opencv,请安装它。在Windows命令行中输入:

SyntaxError: Unexpected token o in JSON at position 1
    at JSON.parse (<anonymous>)
    at parse (/Users/johnseabolt/Desktop/code/PERSONAL/dfpr/node_modules/body-parser/lib/types/json.js:89:19)
    at /Users/johnseabolt/Desktop/code/PERSONAL/dfpr/node_modules/body-parser/lib/read.js:121:18
    at invokeCallback (/Users/johnseabolt/Desktop/code/PERSONAL/dfpr/node_modules/raw-body/index.js:224:16)
    at done (/Users/johnseabolt/Desktop/code/PERSONAL/dfpr/node_modules/raw-body/index.js:213:7)
    at IncomingMessage.onEnd (/Users/johnseabolt/Desktop/code/PERSONAL/dfpr/node_modules/raw-body/index.js:273:7)
    at emitNone (events.js:106:13)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1056:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)

并且导入为

router.post('/create', jwtAuth, jsonParser, (req, res) => {

    const { title, author, content } = req.body;

    if (!title) {
        return res.status(422).json({ message: 'Title is required' }); 
    }

    if (!author) {
        return res.status(422).json({ message: 'Author is required' }); 
    }

    if (!content) {
        return res.status(422).json({ message: 'Content is required' }); 
    }

    return Article
        .create({ title, author, content })
        .then(article => {
            res.status(202).json({ article }); 
        })
        .catch(err => {
            res.status(422).json({ 
                error: err, 
                message: 'There was a problem with your request'
            }); 
        }) 

});