掘金社区

spyder 运行示例,有错误Pinned highlighted

151200***938 发表在策略研究 2020-04-07 15:50:15

策略研究
455
3
0

File "D:\p\lib\importlib_init_.py", line 122, in import_module
raise TypeError(msg.format(name))

TypeError: the 'package' argument is required to perform a relative import for '.Users.zhangguoxiang.Desktop.main'

评论: 3
  • 是把mian.py文件当成包导入到别的py文件里了吗

    2020-04-09 09:06:52
  • @技术支持1 我是直接输入的实例
    from future import print_function, absolute_import, unicode_literals
    from gm.api import *
    def init(context):
    schedule(schedule_func=algo, date_rule='1d', time_rule='14:50:00')
    def algo(context):
    # 购买200股浦发银行股票
    order_volume(symbol='SHSE.600000', volume=200, side=OrderSide_Buy,
    order_type=OrderType_Market,
    position_effect=PositionEffect_Open, price=0)
    if name == 'main':
    run(strategy_id='strategy_1',
    filename=r'C:\Users\zhangguoxiang\Desktop\main.py',
    mode=MODE_BACKTEST, token='22ff94d96116573c05a22e37cb6a878accf14dc2',
    backtest_start_time='2016-06-17 13:00:00',
    backtest_end_time='2017-08-21 15:00:00')

    结果就出现下面问题了
    Traceback (most recent call last):

    File "<ipython-input-5-7ca7369e997c>", line 6, in <module>
    backtest_end_time='2017-08-21 15:00:00')

    File "C:\Users\zhangguoxiang\AppData\Roaming\Python\Python37\site-packages\gm\api\basic.py", line 336, in run
    fmodule = import_module(filename)

    File "D:\p\lib\importlib_init_.py", line 122, in import_module
    raise TypeError(msg.format(name))

    TypeError: the 'package' argument is required to perform a relative import for '.Users.zhangguoxiang.Desktop.main'

    2020-04-09 14:24:11
  • @151200-938 run(strategy_id='strategy_1',
    filename=r'C:\Users\zhangguoxiang\Desktop\main.py',这两个参数有误
    strategy_id是策略ID,策略自动生成,终端上也有
    0_1587375254654_350239d6-6bc2-4c8a-ab5c-06dff953ac38-image.png
    filename是策略文件名,不是路径

    2020-04-20 17:34:45

Looks like your connection to 掘金量化社区 - 量化交易者的策略交流学习社区 was lost, please wait while we try to reconnect.