ricequant / rqalpha

A extendable, replaceable Python algorithmic backtest && trading framework supporting multiple securities
http://rqalpha.io
Other
5.39k stars 1.62k forks source link

win10下update_bundle出错 #101

Closed xuxiong closed 7 years ago

xuxiong commented 7 years ago

环境为:win10,anaconda2,python3.6.1, rqalpha-2.1.2 错误输出如下:

(py36) C:\Users\xux>rqalpha update_bundle -d .rqalpha
尝试 http://7xjci3.com1.z0.glb.clouddn.com/bundles_v2/rqbundle_20170424.tar.bz2 ...
尝试 http://7xjci3.com1.z0.glb.clouddn.com/bundles_v2/rqbundle_20170423.tar.bz2 ...
尝试 http://7xjci3.com1.z0.glb.clouddn.com/bundles_v2/rqbundle_20170422.tar.bz2 ...
尝试 http://7xjci3.com1.z0.glb.clouddn.com/bundles_v2/rqbundle_20170421.tar.bz2 ...
Traceback (most recent call last):
  File "c:\anaconda2\envs\py36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\anaconda2\envs\py36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
         ��     �� {'__name__': '__main__', '__doc__': None, '__package__': '', '__loader__': <zipimporter object "C:\Anaconda2\envs\py36\Scripts\r...
         �� <code object <module> at 0x000001AC21B2AB70, file "C:\Anaconda2\envs\py36\Scripts\rqalpha.exe\__main__.py", line 2>
  File "C:\Anaconda2\envs\py36\Scripts\rqalpha.exe\__main__.py", line 9, in <module>
    sys.exit(entry_point())
    ��        �� <function entry_point at 0x000001AC21B9A158>
    �� <module 'sys' (built-in)>
  File "c:\anaconda2\envs\py36\lib\site-packages\rqalpha\__main__.py", line 66, in entry_point
    cli(obj={})
    �� <click.core.Group object at 0x000001AC2433D668>
  File "c:\anaconda2\envs\py36\lib\site-packages\click\core.py", line 722, in __call__
    return self.main(*args, **kwargs)
           ��          ��       �� {'obj': {'VERBOSE': 0}}
           ��          �� ()
           �� <click.core.Group object at 0x000001AC2433D668>
  File "c:\anaconda2\envs\py36\lib\site-packages\click\core.py", line 697, in main
    rv = self.invoke(ctx)
         ��           �� <click.core.Context object at 0x000001AC21B610F0>
         �� <click.core.Group object at 0x000001AC2433D668>
  File "c:\anaconda2\envs\py36\lib\site-packages\click\core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
           ��               ��                      �� <click.core.Context object at 0x000001AC2434AE10>
           ��               �� <click.core.Context object at 0x000001AC2434AE10>
           �� <function MultiCommand.invoke.<locals>._process_result at 0x000001AC219097B8>
  File "c:\anaconda2\envs\py36\lib\site-packages\click\core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ��          ��                �� <click.core.Context object at 0x000001AC2434AE10>
           ��          �� <click.core.Command object at 0x000001AC2433DC88>
           �� <click.core.Context object at 0x000001AC2434AE10>
  File "c:\anaconda2\envs\py36\lib\site-packages\click\core.py", line 535, in invoke
    return callback(*args, **kwargs)
           ��         ��       �� {'data_bundle_path': '.rqalpha', 'locale': 'zh_Hans_CN'}
           ��         �� ()
           �� <function update_bundle at 0x000001AC24348048>
  File "c:\anaconda2\envs\py36\lib\site-packages\rqalpha\__main__.py", line 77, in update_bundle
    main.update_bundle(data_bundle_path, locale)
    ��                  ��                 �� 'zh_Hans_CN'
    ��                  �� '.rqalpha'
    �� <module 'rqalpha.main' from 'c:\\anaconda2\\envs\\py36\\lib\\site-packages\\rqalpha\\main.py'>
  File "c:\anaconda2\envs\py36\lib\site-packages\rqalpha\main.py", line 164, in update_bundle
    with click.progressbar(length=total_length, label=_(u"downloading ...")) as bar:
  File "c:\anaconda2\envs\py36\lib\site-packages\click\termui.py", line 306, in progressbar
    width=width, color=color)
  File "c:\anaconda2\envs\py36\lib\site-packages\click\_termui_impl.py", line 66, in __init__
    file = _default_text_stdout()
    ��      �� <function _make_cached_stream_func.<locals>.func at 0x000001AC21DB6F28>
    �� None
  File "c:\anaconda2\envs\py36\lib\site-packages\click\_compat.py", line 621, in func
    rv = wrapper_func()
    ��    �� <function get_text_stdout at 0x000001AC219F6048>
    �� None
  File "c:\anaconda2\envs\py36\lib\site-packages\click\_compat.py", line 385, in get_text_stdout
    rv = _get_windows_console_stream(sys.stdout, encoding, errors)
         ��                           ��           ��         �� None
         ��                           ��           �� None
         ��                           �� <module 'sys' (built-in)>
         �� <function _get_windows_console_stream at 0x000001AC21DA2488>
  File "c:\anaconda2\envs\py36\lib\site-packages\click\_winconsole.py", line 261, in _get_windows_console_stream
    func = _stream_factories.get(f.fileno())
           ��                     �� <colorama.ansitowin32.StreamWrapper object at 0x000001AC228329E8>
           �� {0: <function _get_text_stdin at 0x000001AC21D8A620>, 1: <function _get_text_stdout at 0x000001AC21DA2378>, 2: <function _get_te...
TypeError: fileno() takes 0 positional arguments but 1 was given
wh1100717 commented 7 years ago

我尝试搭建环境测试了一下,确实在Python 3.6 下会出现 如上错误,但这个应该是 click 出现了问题。具体的等我详细查看一下的....

xuxiong commented 7 years ago

环境调整为:win10,anaconda2,python2.7, rqalpha-2.1.2 update_bundle正常。

wh1100717 commented 7 years ago

@xuxiong 查看了一下,原因是 colorama 库更新到0.3.8版本,底层覆盖了 sys.stdout .....

其中 ansitowin32.py 文件中定义了如下内容:

class StreamWrapper(object):
    '''
    Wraps a stream (such as stdout), acting as a transparent proxy for all
    attribute access apart from method 'write()', which is delegated to our
    Converter instance.
    '''
    def __init__(self, wrapped, converter):
        # double-underscore everything to prevent clashes with names of
        # attributes on the wrapped stream object.
        self.__wrapped = wrapped
        self.__convertor = converter

    def __getattr__(self, name):
        return getattr(self.__wrapped, name)

    def write(self, text):
        self.__convertor.write(text)

    def fileno():
        raise OSError()

其中 fileno 函数 第一没实现 raise 了一个 OSError 第二 还写错了,少了个self....

从而导致 执行如下命令会报错:

import sys
sys.stdout.fileno()

而... click 包使用了 该函数....

目前 RQAlpha 指定使用 colorama==0.3.6 便可以规避该问题。

您可以指定安装 0.3.6 版本的 colorama 或者稍后更新新版本的RQAlpha 来解决该问题。