这篇文章描述如何在macOS上面装Veighna 3.2.0。
在mac机器上没法使用CTP,而tts提供了CTP的所有接口,所以这里记录一下如何在mac上安装veighna 3.2.0。
首先要装ta-lib
然后
1 pip install -r requirements.txt
最后,进入vnpy源码目录,安装
如果是Linux版本,只需
CTP没法安装,TTS模拟环境也没有办法安装,等后面发布mac版本。
下面文章讲的是veighna 3.0.0的安装流程,目前来看有点老了。
macOS 在mac OS下面安装veighna 3.0.0,Linux类似。我使用的是anaconda下面的python。
创建python 3.10的环境 1 $ conda create -n py310 python=3.10
激活py310环境。
安装vnpy 1 $ pip install -i https://pypi.tuna.tsinghua.edu.cn/simple vnpy
不出意外,在安装ta-lib的时候会出错。
1 2 3 4 5 6 7 8 9 10 11 12 xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun error: command '/usr/bin/clang' failed with exit code 1 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for ta-lib Running setup.py clean for ta-lib Successfully built deap Failed to build ta-lib Installing collected packages: ta-lib, pyzmq, PySide6, pyqtgraph, plotly, install, deap, seaborn, qdarkstyle, vnpy Running setup.py install for ta-lib ... error error: subprocess-exited-with-error
解决mac OS xcrun error, missing xcrun
然后重新安装vnpy,即可以成功安装。
进入vnpy/example/veighna_trader/
,执行run.py
遇到如下问题:
ModuleNotFoundError: No module named 'importlib_metadata'
安装模块。
1 $ pip install importlib_metadata
最后可以成功启动veighna trader界面。不过mac OS无法加载CTP模块。
国内市场用到的绝大部分量化交易接口(如CTP、飞马、飞创、恒生等),其开发商只提供了Windows和Linux的API开发包。 没有Mac版本(无法直接使用)的同时,也没有提供API源代码(无法自行编译),因此这类接口在Mac系统上无法使用(强行加载会报错找不到C++的DLL文件)。 但纯Python接口和REST/WebSocket接口,由于不存在对于C++链接库的依赖,所以在Mac上均可以直接运行。
Windows 10 创建python3.10环境和上面相同。
1 $ pip install -i https://mirrors.aliyun.com/pypi/simple vnpy
安装ta-lib失败。
按官网提供的安装方法安装。
1 2 pip install --extra-index-url http://139.196.190.180 --trusted-host 139.196.190.180 TA_Lib Successfully installed TA-Lib-0.4.24
重新执行上面的安装语句,可能会遇到一个错误,这个错误不会中断安装程序,很容易被忽略,而且最后还能显示安装成功。
这个错误跟deap相关。
1 2 3 4 5 6 7 WARNING: Discarding https://pypi.tuna.tsinghua.edu.cn/packages/af/29/e7f2ecbe02997b16a768baed076f5fc4781d7057cd5d9adf7c94027845ba/deap-1.2.2.tar.gz#sha256=95c63e66d755ec206c80fdb2908851c0bef420ee8651ad7be4f0578e9e909bcf (from https://pypi.tuna.tsinghua.edu.cn/simple/deap/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output. Using cached https://pypi.tuna.tsinghua.edu.cn/packages/b0/9c/a7404777a4cdf5857224051f2ae363d76c3d3b17d27b2caf12ed9bbe6d94/deap-1.2.1.tar.gz (936 kB) ERROR: Command errored out with exit status 1: command: 'C:\ProgramData\Miniconda3\envs\py310\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Simon\\AppData\\Local\\Temp\\pip-install-w5an0dek\\deap_f8336f0a0f4e439d85daec3d2c91d4cb\\setup.py'"'"'; __file__='"'"'C:\\Users\\Simon\\AppData\\Local\\Temp\\pip-install-w5an0dek\\deap_f8336f0a0f4e439d85daec3d2c91d4cb\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\Simon\AppData\Local\Temp\pip-pip-egg-info-jymbv_bj' cwd: C:\Users\Simon\AppData\Local\Temp\pip-install-w5an0dek\deap_f8336f0a0f4e439d85daec3d2c91d4cb\ Complete output (1 lines): error in deap setup command: use_2to3 is invalid.
官方也提供了解决方案。
查看setuptools
版本。
1 2 pip list | findstr setuptools setuptools 58.0.4
需要把setuptools
降低到57版本。
1 2 3 4 5 6 7 8 9 10 11 12 pip install setuptools==57.0.0 Collecting setuptools==57.0.0 Downloading setuptools-57.0.0-py3-none-any.whl (821 kB) |████████████████████████████████| 821 kB 63 kB/s Installing collected packages: setuptools Attempting uninstall: setuptools Found existing installation: setuptools 58.0.4 Uninstalling setuptools-58.0.4: Successfully uninstalled setuptools-58.0.4 Successfully installed setuptools-57.0.0
最近再安装vnpy,就可以安装成功了,如果运行时需要什么模块,再安装就可以了。
需要注意的是,如果使用VSCode来编辑python文件,在使用终端命令中,类型一定要选择