簡體   English   中英

xlwings runpython EOL錯誤

[英]xlwings runpython EOL error

我最近在Mac上安裝了xlwings,目前正在嘗試編寫一個小程序來更新某些數據(通過請求)。 作為測試,我嘗試通過API更新加密貨幣價格並將其寫入excel。 在不使用runpython的情況下,代碼可以正常工作。 但是,一旦我運行VBA代碼,就會出現此錯誤:

 File "<string>", line 1

import sys, os;sys.path.extend(os.path.normcase(os.path.expandvars('/Users/Dennis/Documents/crypto;

                                                                                                  ^

SyntaxError: EOL while scanning string liberal

我搜索了許多主題和論壇,但似乎找不到我的問題的答案。 為了更好的理解,

我的python代碼:

import requests, json
from datetime import datetime
import xlwings as xw

def do():
   parameter = {'convert' : 'EUR'}

   #anfrage über API
   query_ticker = requests.get('https://api.coinmarketcap.com/v1/ticker',   params = parameter)


   #anfragedaten in JSON-format
   data_ticker = query_ticker.json()


   wb = xw.Book.caller()
   ws0 = wb.sheets['holdings']

   for entry in data_ticker:

       # update eth price
       if entry['symbol'] == 'ETH':
        ws0.range('B14').value = float(entry['price_eur'])

       #update btc price
       if entry['symbol'] == 'BTC':
        ws0.range('B15').value = float(entry['price_eur'])

       if entry['symbol'] == 'NEO':
        ws0.range('B16').value = float(entry['price_eur'])

       if entry['symbol'] == 'XRP':
        ws0.range('B17').value = float(entry['price_eur'])

   now = datetime.now()
   write_date = '%s.%s.%s' %(now.day, now.month, now.year)
   write_time = '%s:%s:%s' %(now.hour, now.minute,now.second)

   ws0.range('B2').value = write_date
   ws0.range('B3').value = write_time

   wb.save('holdings.xlsm')
   #wb.close()

這是我的VBA代碼:

Sub update_holdings()
    RunPython ("import update_holdings; update_holdings.do()")
End Sub

解決了這個。 我只是想將解決方案發布給可能遇到相同問題的任何人。

我去檢查了我的xlwings.conf文件,以查看“ INTERPRETER”和“ PYTHONPATH”的設置。 我從未對此進行編輯,但是,其格式不正確。

正確的格式是:

"INTERPRETER","pythonw"
"PYTHONPATH",""

我的配置文件是這樣設置的:

"PYTHONPATH","
"
"INTERPRETER","Python"

另外,默認情況下,我的python的路徑設置不正確。 即使我的命令行可與Anaconda python 3.6一起使用,“ pythonw”仍使用.bash_profile中設置的解釋程序,該解釋程序引用了macOS預先安裝的python 2.7。 編輯配置文件“ INTERPRETER”解決了此問題。

感謝大家。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM