python - 谷歌云虚拟机 - 安装 openCV

标签 python google-app-engine opencv google-cloud-platform dockerfile

我使用带有 Python 的 Google App Engine 来托管一些后端脚本并将数据存储在数据存储区中,我需要利用 openCV 进行一些更高级的媒体操作。

我正在尝试切换到 Google Cloud VM Platform,但我无法理解如何安装 openCV。

今天早些时候,我在 VM Cloud Shell 上尝试过:

sudo apt-get install python-opencv

这似乎有效,在列出我的 python 模块后我得到了:

help> modules

Please wait a moment while I gather a list of all available modules...

/usr/local/lib/python2.7/dist-packages/IPython/kernel/__init__.py:13: ShimWarning: The `IPython.kernel` package has been deprecated. You should import from ipykernel or jupyter_client instead.
  "You should import from ipykernel or jupyter_client instead.", ShimWarning)
BaseHTTPServer      audiodev            importlib           setuptools
Bastion             audioop             imputil             sgmllib
CDROM               autoreload          inspect             sha
CGIHTTPServer       base64              io                  shelve
Canvas              bdb                 ipython_genutils    shlex
ConfigParser        binascii            itertools           shutil
Cookie              binhex              json                signal
DLFCN               bisect              keyword             simplegeneric
Dialog              bsddb               lib2to3             site
DocXMLRPCServer     bz2                 linecache           sitecustomize
FileDialog          cPickle             linuxaudiodev       six
FixTk               cProfile            locale              smtpd
HTMLParser          cStringIO           logging             smtplib
IN                  calendar            macpath             sndhdr
IPython             cgi                 macurl2path         socket
MimeWriter          cgitb               mailbox             spwd
Queue               chardet             mailcap             sqlite3
ScrolledText        chunk               markupbase          sre
SimpleDialog        cmath               marshal             sre_compile
SimpleHTTPServer    cmd                 math                sre_constants
SimpleXMLRPCServer  code                md5                 sre_parse
SocketServer        codecs              meld3               ssl
StringIO            codeop              mercurial           stat
TYPES               collections         mhlib               statvfs
Tix                 colorama            mimetools           storemagic
Tkconstants         colorsys            mimetypes           string
Tkdnd               commands            mimify              stringold
Tkinter             compileall          mmap                stringprep
UserDict            compiler            modulefinder        strop
UserList            contextlib          multifile           struct
UserString          cookielib           multiprocessing     subprocess
_LWPCookieJar       copy                mutex               sunau
_MozillaCookieJar   copy_reg            netrc               sunaudio
__builtin__         crcmod              new                 supervisor
__future__          crypt               nis                 symbol
_abcoll             csv                 nntplib             sympyprinting
_ast                ctypes              ntpath              symtable
_bisect             curses              nturl2path          sys
_bsddb              cv                  numbers             sysconfig
_codecs             cv2                 numpy               syslog
_codecs_cn          cythonmagic         oauth2client        tabnanny
_codecs_hk          datetime            opcode              tarfile
_codecs_iso2022     dbhash              operator            telnetlib
_codecs_jp          dbm                 optparse            tempfile
_codecs_kr          debconf             os                  termios
_codecs_tw          decimal             os2emxpath          test
_collections        decorator           ossaudiodev         test_path
_csv                difflib             parser              tests
_ctypes             dircache            path                textwrap
_ctypes_test        dis                 pdb                 this
_curses             distlib             pexpect             thread
_curses_panel       distutils           pickle              threading
_elementtree        doctest             pickleshare         time
_functools          dumbdbm             pickletools         timeit
_hashlib            dummy_thread        pip                 tkColorChooser
_heapq              dummy_threading     pipes               tkCommonDialog
_hotshot            easy_install        pkg_resources       tkFileDialog
_io                 email               pkgutil             tkFont
_json               encodings           platform            tkMessageBox
_locale             ensurepip           plistlib            tkSimpleDialog
_lsprof             errno               popen2              toaiff
DocXMLRPCServer     bz2                 linecache           sitecustomize
_markerlib          exceptions          poplib              token
_md5                fcntl               posix               tokenize
_multibytecodec     filecmp             posixfile           trace
_multiprocessing    fileinput           posixpath           traceback
_osx_support        fnmatch             pprint              traitlets
_pyio               formatter           profile             ttk
_random             fpectl              pstats              tty
_sha                fpformat            pty                 turtle
_sha256             fractions           ptyprocess          types
_sha512             ftplib              pwd                 unicodedata
_socket             functools           py_compile          unittest
_sqlite3            future_builtins     pyasn1              urllib
_sre                gc                  pyasn1_modules      urllib2
_ssl                genericpath         pyclbr              urllib3
_strptime           getopt              pydoc               urlparse
_struct             getpass             pydoc_data          user
_symtable           gettext             pyexpat             uu

如您所见,列出了 cv 和 cv2。然后我尝试了:

>>> from cv2 import *

我也试过:

>>> import cv2

而且两者似乎都正确导入了模块。

然而,几个小时后,我再次尝试导入 cv2,但没有找到,所以我再次运行模块检查并得到:

help> modules

Please wait a moment while I gather a list of all available modules...

/usr/local/lib/python2.7/dist-packages/IPython/kernel/__init__.py:13: ShimWarning: The `IPython.kernel` package has been deprecated. You should import from ipykernel or jupyter_client instead.
  "You should import from ipykernel or jupyter_client instead.", ShimWarning)
BaseHTTPServer      base64              jinja2              sets
Bastion             bdb                 json                setuptools
CDROM               binascii            jsonschema          sgmllib
CGIHTTPServer       binhex              jupyter             sha
Canvas              bisect              jupyter_client      shelve
ConfigParser        bsddb               jupyter_console     shlex
Cookie              bz2                 jupyter_core        shutil
DLFCN               cPickle             keyword             signal
Dialog              cProfile            lib2to3             simplegeneric
DocXMLRPCServer     cStringIO           linecache           singledispatch
FileDialog          calendar            linuxaudiodev       singledispatch_helpers
FixTk               certifi             locale              site
HTMLParser          cgi                 logging             sitecustomize
IN                  cgitb               macpath             six
IPython             chardet             macurl2path         smtpd
MimeWriter          chunk               mailbox             smtplib
Queue               cmath               mailcap             sndhdr
ScrolledText        cmd                 markupbase          socket
SimpleDialog        code                markupsafe          spwd
SimpleHTTPServer    codecs              marshal             sqlite3
SimpleXMLRPCServer  codeop              math                sre
SocketServer        collections         md5                 sre_compile
StringIO            colorama            meld3               sre_constants
TYPES               colorsys            mercurial           sre_parse
Tix                 commands            mhlib               ssl
Tkconstants         compileall          mimetools           stat
Tkdnd               compiler            mimetypes           statvfs
Tkinter             contextlib          mimify              storemagic
UserDict            cookielib           mistune             string
UserList            copy                mmap                stringold
UserString          copy_reg            modulefinder        stringprep
_LWPCookieJar       crcmod              multifile           strop
_MozillaCookieJar   crypt               multiprocessing     struct
__builtin__         csv                 mutex               subprocess
__future__          ctypes              nbconvert           sunau
_abcoll             curses              nbformat            sunaudio
_ast                cythonmagic         netrc               supervisor
_bisect             datetime            new                 symbol
_bsddb              dbhash              nis                 sympyprinting
_codecs             dbm                 nntplib             symtable
_codecs_cn          debconf             notebook            sys
_codecs_hk          decimal             ntpath              sysconfig
_codecs_iso2022     decorator           nturl2path          syslog
_codecs_jp          difflib             numbers             tabnanny
_codecs_kr          dircache            oauth2client        tarfile
_codecs_tw          dis                 opcode              telnetlib
_collections        distlib             operator            tempfile
_csv                distutils           optparse            terminado
_ctypes             doctest             os                  termios
_ctypes_test        dumbdbm             os2emxpath          test
_curses             dummy_thread        ossaudiodev         test_path
_curses_panel       dummy_threading     parser              tests
_elementtree        easy_install        path                textwrap
_functools          email               pdb                 this
_hashlib            encodings           pexpect             thread
_heapq              ensurepip           pickle              threading
_hotshot            errno               pickleshare         time
_io                 exceptions          pickletools         timeit
_json               fcntl               pip                 tkColorChooser
_locale             filecmp             pipes               tkCommonDialog
_lsprof             fileinput           pkg_resources       tkFileDialog
_markerlib          fnmatch             pkgutil             tkFont
_md5                formatter           platform            tkMessageBox
_multibytecodec     fpectl              plistlib            tkSimpleDialog
_multiprocessing    fpformat            popen2              toaiff
_osx_support        fractions           poplib              token
_pyio               ftplib              posix               tokenize
_random             functools           posixfile           tornado
_sha                functools32         posixpath           trace
_sha256             future_builtins     pprint              traceback
_sha512             gc                  profile             traitlets
_socket             genericpath         pstats              ttk
_sqlite3            getopt              pty                 tty
_sre                getpass             ptyprocess          turtle
_ssl                gettext             pwd                 types
_strptime           glob                py_compile          unicodedata
Canvas              bisect              jupyter_client      shelve
_struct             grp                 pyasn1              unittest
_symtable           gzip                pyasn1_modules      urllib
_sysconfigdata      hashlib             pyclbr              urllib2
_sysconfigdata_nd   heapq               pydoc               urllib3
_testcapi           hgext               pydoc_data          urlparse
_threading_local    hmac                pyexpat             user
_warnings           hotshot             pygments            uu
_weakref            html5lib            qtconsole           uuid
_weakrefset         htmlentitydefs      quopri              warnings
abc                 htmllib             random              wave
aifc                httplib             re                  weakref
antigravity         httplib2            readline            webbrowser
anydbm              ihooks              repr                whichdb
argparse            imaplib             requests            wsgiref
array               imghdr              resource            xdrlib
ast                 imp                 rexec               xml
asynchat            importlib           rfc822              xmllib
asyncore            imputil             rlcompleter         xmlrpclib
atexit              inspect             rmagic              xxsubtype
audiodev            io                  robotparser         zipfile
audioop             ipykernel           rsa                 zipimport
autoreload          ipython_genutils    runpy               zlib
backports           ipywidgets          sched               zmq
backports_abc       itertools           select              

我的 openCV 安装出了什么问题?

如果有人知道有关如何正确安装 openCV 并将其导入我的 python 脚本的完整文档帮助,请发布该链接!我从谷歌云文档中知道herehere我应该能够在我的 VM 上使用 openCV。

关于如何设置 Dockerfile 和 requirements.txt 文件以正确使用 openCV 的一些更详细的说明也会很有帮助。同样,上面链接的 Google Cloud 文档中引用了这一点,但从未详细解释过。

谢谢!

最佳答案

Google Cloud Shell只是一个virtual machine正在运行 Google Cloud SDK .这是运行 gcloud 命令以与您的 Google Cloud 项目资源进行交互和管理的快速方法。但它不包含您的实际项目资源。

Cloud Shell 的 session 仅在其处于事件状态时保留,并在一小时不活动后终止。因此,在 Cloud Shell 虚拟机上导入 openCV 完全独立于您的项目,不会以任何方式持久化到项目中。

为了将 openCV 应用程序部署到 App Engine,您需要使用“gcloud app deploy” ' openCV 应用程序目录中的命令。

作为 openCV 的替代品,我们现在提供 Machine Learning products它为您的应用程序提供了分析图像、视频、语音、文本等的能力。

关于python - 谷歌云虚拟机 - 安装 openCV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35107551/

相关文章:

python - 如何在 Sharepoint 中更新文档的元数据? (Linux -> Web 服务 -> Sharepoint)

python - PySide2:如何使装饰槽在其工作线程上执行?

java - 如何在一个实体组中创建实体?

c++ - 调整视频捕获的分辨率

python - Ipython cv2.imwrite() 不保存图像

c++ - 将 mat vector 转换为 Mat 文件以便使用 opencv svm

python - Flask 应用程序在部署到 pythonanywhere 时无法运行

c++ - python中具有静态成员的模板上的swig undefined symbol

python - python flex环境导入报错google.appengine.api

node.js - 在 Google App Engine 上部署 Vuejs - webpack webapp