ImportError:无法导入名称_args_from_interpreter_flags

时间:2017-11-24 04:02:03

标签: python google-cloud-platform google-cloud-vision

对于应用程序,我必须使用Google Vision API。 我可以使用from google.cloud import vision并在我的计算机上进行图像分析。 但是,当我在开发服务器上部署我的应用程序时,我收到错误:

File "C:\MyApp\detect.py", line 26, in <module>
    from google.cloud import vision
  File "C:\Anaconda2\lib\site-packages\google\cloud\vision\__init__.py", line 34, in <module>
    __version__ = get_distribution('google-cloud-vision').version
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\setuptools-0.6c11\pkg_resources.py", line 311, in get_distribution
    if isinstance(dist,Requirement): dist = get_provider(dist)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\setuptools-0.6c11\pkg_resources.py", line 197, in get_provider
    return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\setuptools-0.6c11\pkg_resources.py", line 666, in require
    needed = self.resolve(parse_requirements(requirements))
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\setuptools-0.6c11\pkg_resources.py", line 565, in resolve
    raise DistributionNotFound(req)  # XXX put more info here
DistributionNotFound: google-cloud-vision

当我创建包含以下内容的appengine_config.py文件时

from google.appengine.ext import vendor
vendor.add('C:\Anaconda2\Lib\site-packages')

我收到错误:

File "C:\Users\MyApp\detect.py", line 26, in <module>
    from google.cloud import vision
  File "C:\Anaconda2\lib\site-packages\google\cloud\vision\__init__.py", line 36, in <module>
    from google.cloud.vision.client import Client
  File "C:\Anaconda2\lib\site-packages\google\cloud\vision\client.py", line 23, in <module>
    from google.cloud.vision._gax import _GAPICVisionAPI
  File "C:\Anaconda2\lib\site-packages\google\cloud\vision\_gax.py", line 17, in <module>
    from google.cloud.gapic.vision.v1 import image_annotator_client
  File "C:\Anaconda2\lib\site-packages\google\cloud\gapic\vision\v1\image_annotator_client.py", line 31, in <module>
    from google.gax import api_callable
  File "C:\Anaconda2\lib\site-packages\google\gax\__init__.py", line 36, in <module>
    import multiprocessing as mp
  File "C:\Anaconda2\lib\multiprocessing\__init__.py", line 65, in <module>
    from multiprocessing.util import SUBDEBUG, SUBWARNING
  File "C:\Anaconda2\lib\multiprocessing\util.py", line 41, in <module>
    from subprocess import _args_from_interpreter_flags
ImportError: cannot import name _args_from_interpreter_flags

当我尝试下面链接中提到的黑客时:
https://github.com/GoogleCloudPlatform/google-cloud-python/issues/1893
https://github.com/googleapis/gax-python/issues/149
https://gist.github.com/nilleb/419122f2f6f1228650dd2dccbd01c5af

我收到错误:

File "C:\Users\MyApp\detect.py", line 11, in <module>
    class DummyProcessing(ModuleType):
NameError: name 'ModuleType' is not defined

然后我按照这里的指示:https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27#copying_a_third-party_library
并使用此命令:

pip install -t lib google-cloud-vision==0.28.0

更新appengine_config.py档案:

from google.appengine.ext import vendor
vendor.add('lib')

我收到错误:

File "C:\Users\MyApp\detect.py", line 26, in <module>
    from google.cloud import vision
  File "C:\Anaconda2\lib\site-packages\google\cloud\vision\__init__.py", line 36, in <module>
    from google.cloud.vision.client import Client
  File "C:\Anaconda2\lib\site-packages\google\cloud\vision\client.py", line 23, in <module>
    from google.cloud.vision._gax import _GAPICVisionAPI
  File "C:\Anaconda2\lib\site-packages\google\cloud\vision\_gax.py", line 17, in <module>
    from google.cloud.gapic.vision.v1 import image_annotator_client
  File "C:\Anaconda2\lib\site-packages\google\cloud\gapic\vision\v1\image_annotator_client.py", line 31, in <module>
    from google.gax import api_callable
  File "C:\Anaconda2\lib\site-packages\google\gax\__init__.py", line 36, in <module>
    import multiprocessing as mp
  File "C:\Anaconda2\lib\multiprocessing\__init__.py", line 65, in <module>
    from multiprocessing.util import SUBDEBUG, SUBWARNING
  File "C:\Anaconda2\lib\multiprocessing\util.py", line 41, in <module>
    from subprocess import _args_from_interpreter_flags
ImportError: cannot import name _args_from_interpreter_flags

然后我按照这里的指示: Using gcloud-python in GAE

并使用此命令:

pip install -t vendor google-cloud-vision==0.28.0

我从这里复制了appengine_config.pydarth.py个文件: https://github.com/dhermes/test-gcloud-on-gae/tree/8a850fb8b5676ca03e07c4f9dcfba5efb8c77b0a/application

我收到错误:

File "C:\Users\MyApp\detect.py", line 26, in <module>
    from google.cloud import vision
  File "C:\Anaconda2\lib\site-packages\google\cloud\vision\__init__.py", line 36, in <module>
    from google.cloud.vision.client import Client
  File "C:\Anaconda2\lib\site-packages\google\cloud\vision\client.py", line 23, in <module>
    from google.cloud.vision._gax import _GAPICVisionAPI
  File "C:\Anaconda2\lib\site-packages\google\cloud\vision\_gax.py", line 17, in <module>
    from google.cloud.gapic.vision.v1 import image_annotator_client
  File "C:\Anaconda2\lib\site-packages\google\cloud\gapic\vision\v1\image_annotator_client.py", line 31, in <module>
    from google.gax import api_callable
  File "C:\Anaconda2\lib\site-packages\google\gax\__init__.py", line 36, in <module>
    import multiprocessing as mp
  File "C:\Anaconda2\lib\multiprocessing\__init__.py", line 65, in <module>
    from multiprocessing.util import SUBDEBUG, SUBWARNING
  File "C:\Anaconda2\lib\multiprocessing\util.py", line 41, in <module>
    from subprocess import _args_from_interpreter_flags
ImportError: cannot import name _args_from_interpreter_flags

我不知道接下来该做什么。我现在完全陷入困境。

1 个答案:

答案 0 :(得分:1)

回溯表明该库安装在本地python系统(C:\Anaconda2\lib\site-packages\google\cloud\vision)中,而不是应用程序本身,因为它应该用于标准的env GAE应用程序。

来自Google Cloud Vision API Client Library for Python

  

App Engine

     

由于App Engine Python runtime environment中未安装Python客户端库,因此它们必须像{3}}一样{3.}}。

来自vendored into your application

  

使用不在内置列表中的第三方库   与运行时捆绑在一起的库:

     
      
  • 创建一个目录来存储您的第三方库,例如lib/

    mkdir lib
    
  •   
  • 使用带有-t <directory>标志的pip(版本6或更高版本)将库复制到您在上一步中创建的文件夹中。对于   例如:

    pip install -t lib/ <library_name>
    
         

    ...

  •   

按照整个销售程序重新尝试。

但是根据您引用的Copying a third-party library评论可能必须等待该问题得到解决:

  App引擎标准尚不支持

@nilleb grpc。