GCP Python3启动脚本问题

时间:2018-01-08 21:55:22

标签: python google-compute-engine gcp google-cloud-console

我在Google Cloud Compute Instances上使用了启动脚本:

setsid python home/junaid_athar/pull.py

当我在根目录下登录时,我可以在VM上运行以下脚本:

setsid python3 home/junaid_athar/btfx.py

然而,当我将setsid python3 home / junaid_athar / btfx.py添加到启动脚本时,它会抛出错误说:

ImportError: cannot import name 'opentype'

当我登录时,相同的脚本运行正常,但是当我将其作为启动脚本运行时,它不会运行,为什么以及如何解决它?

更新:我对编程非常陌生,而且还要破解。这是脚本:

import logging
import time
import sys
import json
from btfxwss import BtfxWss
from google.cloud import bigquery

log = logging.getLogger(__name__)

fh = logging.FileHandler('/home/junaid_athar/test.log')
fh.setLevel(logging.CRITICAL)
sh = logging.StreamHandler(sys.stdout)
sh.setLevel(logging.CRITICAL)

log.addHandler(sh)
log.addHandler(fh)
    logging.basicConfig(level=logging.DEBUG, handlers=[fh, sh])

def stream_data(dataset_id, table_id, json_data):
    bigquery_client = bigquery.Client()
    dataset_ref = bigquery_client.dataset(dataset_id)
    table_ref = dataset_ref.table(table_id)
    data = json.loads(json_data)

# Get the table from the API so that the schema is available.
table = bigquery_client.get_table(table_ref)

rows = [data]
errors = bigquery_client.create_rows(table, rows)

wss=BtfxWss()
wss.start()

while not wss.conn.connected.is_set():
    time.sleep(2)

# Subscribe to some channels
wss.subscribe_to_trades('BTCUSD')

# Do something else
t = time.time()
while time.time() - t < 5:
    pass

# Accessing data stored in BtfxWss:
trades_q = wss.trades('BTCUSD')  # returns a Queue object for the pair.
while True:
    while not trades_q.empty():
        item=trades_q.get()
        if item[0][0]=='te':
            json_data={'SEQ':item[0][0], 'ID':item[0][1][0], 'TIMESTAMP':int(str(item[0][1][1])[:10]) , 'PRICE':item[0][1][3], 'AMOUNT':item[0][1][2], 'UNIQUE_TS':item[0][1][1], 'SOURCE':'bitfinex'}
            stream_data('gdax','btfxwss', json.dumps(json_data))
# Unsubscribing from channels:
wss.unsubscribe_from_trades('BTCUSD')

# Shutting down the client:
wss.stop()

我在标准的1-CPU 3.75mem机器上运行它。 (Debian GNU / Linux 9(拉伸))。

我认为问题在于python3&amp;的安装目录。模块以及运行启动脚本与登录机器之间的区别 - 如何解决?

1 个答案:

答案 0 :(得分:1)

弄清楚发生了什么。启动脚本作为(在?)根目录运行。我在启动脚本的开头添加了select * from srcTable s where exists ( select 1 from ( SELECT keypart1, keypart2, row_number() over( partition by keypart1, keypart2 ) seq FROM srcTable t WHERE -- (whatever additional filtering you want) ) t where seq > 1 AND t.keypart1 = s.keypart1 AND t.keypart2 = s.keypart2 ) ,它就像我被SSH连接到服务器一样。一切都很好,谢谢大家的帮助!