Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 谷歌云库不工作(导入错误)_Python 2.7_Google App Engine_Google Cloud Platform_Google Cloud Pubsub_Client Library - Fatal编程技术网

Python 2.7 谷歌云库不工作(导入错误)

Python 2.7 谷歌云库不工作(导入错误),python-2.7,google-app-engine,google-cloud-platform,google-cloud-pubsub,client-library,Python 2.7,Google App Engine,Google Cloud Platform,Google Cloud Pubsub,Client Library,我试图使用云发布/订阅从一个主题中提取消息数据,但每次我都会收到一个重要的提示 ImportError: dynamic module does not define init function (init_psutil_linux) 这是我的环境信息: 应用程序引擎标准环境 蟒蛇2.7 这是我的代码: import logging import json # from datetime import datetime, timedelta import time # Imports t

我试图使用云发布/订阅从一个主题中提取消息数据,但每次我都会收到一个重要的提示

ImportError: dynamic module does not define init function (init_psutil_linux)
这是我的环境信息:

  • 应用程序引擎标准环境
  • 蟒蛇2.7
这是我的代码:

import logging
import json
# from datetime import datetime, timedelta
import time

# Imports the Google Cloud client library
from google.cloud import pubsub_v1

import webapp2


class PullMessageData(webapp2.RequestHandler):
    """Pull Pub/Sub Message Data."""

    def get(self):
        self.response.headers['Content-Type'] = 'application/json'

        try:
            subscriber_name = 'subscriber_name'

            # pull subscription message
            pull_message_data(subscriber_name)
            self.response.write(json.dumps({'status': 'OK'}))

        except Exception, e:
            logging.exception(str(e))
            self.response.write(json.dumps({'status': 'ERROR'}))


def pull_message_data(subscriber_name):
    """pull message data from pubsub."""

    # instantiate the pubsub client for a default credential
    subscriber = pubsub_v1.SubscriberClient()

    # callback function for processing the Message Data
    def callback(message):           

        # process data
        print('Received message: {}'.format(message.data))

        # ack the message after processing
        message.ack()

    # Limit the subscriber to only have 5000 outstanding messages at a time.
    flow_control = pubsub_v1.types.FlowControl(max_messages=3)
    # pull message
    subscriber.subscribe(
        subscriber_name, callback=callback, flow_control=flow_control)

    # The subscriber is non-blocking, so we must keep the main thread from
    # exiting to allow it to process messages in the background.
    print('Listening for messages on {}'.format(subscriber_name))
    while True:
        time.sleep(10)
我遵循了 但在我部署之后,我不断收到一条消息,上面说:

(/base/data/home/runtimes/python27_experiment/python27_lib/versions/1/google/appengine/runtime/wsgi.py:263)
Traceback (most recent call last):
  File "/base/data/home/runtimes/python27_experiment/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/base/data/home/runtimes/python27_experiment/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/base/data/home/runtimes/python27_experiment/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
  File "/base/data/home/apps/b~ups/1.404014226174083542/main.py", line 4, in <module>
    import pull_data
  File "/base/data/home/apps/b~ups/1.404014226174083542/pull_data.py", line 9, in <module>
    from google.cloud import pubsub_v1
  File "/base/data/home/apps/b~ups/1.404014226174083542/libs/google/cloud/pubsub_v1/__init__.py", line 17, in <module>
    from google.cloud.pubsub_v1 import types
  File "/base/data/home/apps/b~ups/1.404014226174083542/libs/google/cloud/pubsub_v1/types.py", line 20, in <module>
    import psutil
  File "/base/data/home/apps/b~ups/1.404014226174083542/libs/psutil/__init__.py", line 91, in <module>
    from . import _pslinux as _psplatform
  File "/base/data/home/apps/b~ups/1.404014226174083542/libs/psutil/_pslinux.py", line 26, in <module>
    from . import _psutil_linux as cext
ImportError: dynamic module does not define init function (init_psutil_linux)

请有人帮助找出问题所在。…

它看起来无法加载
psutils
可能尝试
pip安装--升级psutils
它看起来无法加载
psutils
可能尝试
pip安装--升级psutils
import os
import webapp2
import pull_data


app = webapp2.WSGIApplication([
    ('/pull', pull_data.PullMessageData),
], debug=True)