I was using Google App Engine with Python to host some backend scripts and store data in the datastore, and I need to utilize openCV for some more advanced media manipulation.
I am trying to switch over to a Google Cloud VM Platform and I am having trouble understanding how to install openCV.
Earlier today, on the VM Cloud Shell I tried:
sudo apt-get install python-opencv
which seemed to work, and after listing my python modules I got:
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
As you can see, cv and cv2 are listed. I then tried:
>>> from cv2 import *
and I also tried:
>>> import cv2
and both seemed to properly import the module.
However, hours later I tried to import cv2 again, and it wasn't found, so I ran a module check again and got:
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
What happened to my openCV installation?
If someone knows of a full documentation help on how to properly install openCV and import it into my python scripts, please post that link! I know from Google Cloud documentation here and here that I should be able to use openCV on my VM.
It would also be helpful to have some more detailed instructions on how to setup the Dockerfile and requirements.txt files to properly use openCV. Again, this is referenced in the above linked Google Cloud documentation, but never explained in detail.
Thanks!
The Google Cloud Shell is simply a virtual machine that is running the Google Cloud SDK. It is a quick way to run gcloud commands to interact with and manage your Google Cloud Project resources. It does not contain your actual project resources though.
The session of the Cloud Shell is only persisted while it is active, and terminates after an hour of inactivity. Therefore, importing openCV on the Cloud Shell virtual machine is completely separate from your project and is not persisted to it in any way.
In order to deploy your openCV application to App Engine, you would need to use the 'gcloud app deploy' command in the directory of your openCV app.
As an alternative to openCV, we now offer Machine Learning products which provides the ability for your application to analyze images, videos, speech, text, and more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With