vnpy_ubuntu18下vnpy的安装

vnpy1.9版本

主要参考:https://github.com/vnpy/vnpy/wiki/Ubuntu%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85s

1,创建conda环境

conda create -n vnpy27 python=2.7
source activate vnpy27

2,env下安装

pip install future

3,切换到系统下面安装(非env环境)

系统默认其实也是ana的环境,是ana就ana吧

sudo apt-get install git
sudo apt-get install mongodb
sudo apt-get install libboost-all-dev
sudo apt-get install cmake
sudo apt-get install libsnappy-dev
sudo apt-get install python-snappy

4,系统环境下安装

sudo apt-get install build-essential
sudo apt-get install python-dev

5,env下安装

source activate vnpy27

长期支持版git地址i:https://github.com/vnpy/vnpy/tree/v1.9.2-LTS
切换到自己之前的git clone项目中,切换分之即可
cd ~/PYTHON/vnpy
git checkout v1.9.2-LTS
bash install.sh
–是否安装CTP接口,yes
–有几个输入错了,输了大写Y,貌似认为n了
重新安装,全部回车(y)

报错:
File “build/bdist.linux-x86_64/egg/vnpy/api/rest/rest_client.py”, line 28
method: str,
暂不理会

cd ~/PYTHON/vnpy/examples/VnTrader

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
python run.py  
报错:
File "/home/john/anaconda3/envs/vnpy27/lib/python2.7/site-packages/vnpy-1.9.2-py2.7.egg/vnpy/event/eventEngine.py", line 11, in <module>
from qtpy.QtCore import QTimer
File "/home/john/anaconda3/envs/vnpy27/lib/python2.7/site-packages/qtpy/__init__.py", line 208, in <module>
raise PythonQtError('No Qt bindings could be found')
qtpy.PythonQtError: No Qt bindings could be found
进入python窗口,import qtpy确实无法import

可能原因:由于在ananconda中安装,所以部分系统自带的包,无法使用(或版本不对),可能需要独立安装下
参考教程中的安装pyqt4,部分
ana环境中执行:
sudo apt-get install qt4-dev-tools
sudo apt-get install libqwt5-qt4 libqwt5-qt4-dev
之前自己已下载的
cd ~/下载/sip-4.19.8
sudo python configure.py
sudo make install

cd ~/下载/PyQt4_gpl_x11-4.12.1
sudo python configure-ng.py
sudo make
sudo make install
依然不行。

百度下报错提示:qtpy.PythonQtError: No Qt bindings could be found
参考:https://github.com/spyder-ide/spyder/issues/3545
执行:
pip uninstall spyder
pip install spyder==3.2.1
报错:pylint requires Python '>=3.4.*' but the running Python is 2.7.11
忽略,不使用这种解决方式。

参考:https://github.com/spyder-ide/spyder/issues/4078
执行:conda install pyqt
执行python
import qtpy
成功!

cd ~/PYTHON/vnpy/examples/VnTrader
python run.py
报错:
File “/home/john/anaconda3/envs/vnpy27/lib/python2.7/site-packages/vnpy-1.9.2-py2.7.egg/vnpy/api/rest/RestClient.py”, line 11, in
from enum import Enum
ImportError: No module named enum
pip install enum
成功!

cd ~/PYTHON/vnpy/examples/VnTrader
python run.py
报错:
File “/home/john/anaconda3/envs/vnpy27/lib/python2.7/site-packages/vnpy-1.9.2-py2.7.egg/vnpy/api/rest/RestClient.py”, line 12, in
from typing import Any, Callable, Optional
ImportError: No module named typing
pip install typing
成功

cd ~/PYTHON/vnpy/examples/VnTrader
python run.py
报错:
File “/home/john/anaconda3/envs/vnpy27/lib/python2.7/site-packages/vnpy-1.9.2-py2.7.egg/vnpy/api/xtp/init.py”, line 4, in
from .vnxtpquote import QuoteApi
ImportError: libsodium.so.18: cannot open shared object file: No such file or directory
参考:https://mrxn.net/Linux/541.html
执行:
find / -name “libsodium.so.18” 2>/dev/null
sudo ln -sf /home/john/anaconda3/pkgs/libsodium-1.0.10-0/lib/libsodium.so.18 /usr/lib/libsodium.so.18
sudo ldconfig
python run.py
依然是同样的报错:
File “/home/john/anaconda3/envs/vnpy27/lib/python2.7/site-packages/vnpy-1.9.2-py2.7.egg/vnpy/api/xtp/init.py”, line 4, in
from .vnxtpquote import QuoteApi
ImportError: libsodium.so.18: cannot open shared object file: No such file or directory
参考:https://blog.csdn.net/baidu_27518829/article/details/88383775
执行:
conda install -c conda-forge libsodium
python run.py
依然是同样的报错。
参考:https://github.com/vnpy/vnpy/issues/1364
执行:
sudo apt-get install libsodium-dev
cd /home/john/PYTHON/vnpy/vnpy/api/xtp
bash build.sh
python run.py
依然是同样的报错。
参考:同上
执行:
sudo gedit run.py
注释掉加载xtpGateway的代码

python run.py
报错:
File “/home/john/anaconda3/envs/vnpy27/lib/python2.7/site-packages/vnpy-1.9.2-py2.7.egg/vnpy/rpc/vnrpc.py”, line 7, in
import zmq
ImportError: No module named zmq
执行:pip install zmq

python run.py
报错:
File “run.py”, line 65, in main
me.addGateway(xtpGateway)
NameError: global name ‘xtpGateway’ is not defined
执行:sudo gedit run.py
有个地方漏掉了,没注释干净
python run.py
启动起来了,但是没有行情,有账户信息没有配置

vnpy1.9问题补充(20190510接上)

卸载旧vnpy1.9

卸载之前pip安装的vnpy1.9版本,否则和代码中重复了,不知道执行代码还是包里的vnpy

1
pip uninstall vnpy

报错No module named matplotlib

1
2
3
4
报错:ImportError: No module named matplotlib.ticker

解决:
conda install matplotlib

报错No module named statsmodels

1
2
3
4
5
  File "/root/anaconda3/envs/vnpy27/lib/python2.7/site-packages/vnpy-1.9.2-py2.7.egg/vnpy/trader/app/ctaStrategy/ctaBacktesting.py", line 38, in <module>
import statsmodels.api as sm # 最小二
ImportError: No module named statsmodels.api
解决:
conda install statsmodels

报错cannot import name AbstractMethodError

1
2
3
4
5
6
7
报错:
File "/root/anaconda3/envs/vnpy27/lib/python2.7/site-packages/pandas/core/groupby/groupby.py", line 23, in <module>
from pandas.errors import AbstractMethodError
ImportError: cannot import name AbstractMethodError

解决
conda install pandas=0.24.2

报错:/usr/include/features.h:424:12: fatal error: sys/cdefs.h: 没有那个文件或目录

解决:sudo apt-get –reinstall install libc6 libc6-dev
参考:https://askubuntu.com/questions/470796/fatal-error-sys-cdefs-h-no-such-file-or-directory

安装mpl_finance

pip install mpl_finance

安装PyJWT

pip install PyJWT

合并最新192穿透测试版

1
2
3
4
5
6
7
8
9
10
11
12
13
14
upstream 相关设置
git remote add upstream https://github.com/vnpy/vnpy.git
同步本机分支v1.9.2-LTS
git checkout v1.9.2-LTS
git merge upstream/v1.9.2-LTS
同步本机分支master
git checkout master
git merge upstream/master
切断upstream
git remote rm upstream

合并分支v1.9.2-LTS->yuan_vnpy19
git checkout yuan_vnpy19
git merge v1.9.2-LTS

路径:PYTHON/vnpy19/vnpy/api/ctp
执行:bash build.sh
报错:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CTPAPI_MD_LIBRARY
linked by target "vnctpmd" in directory /home/john/PYTHON/vnpy19/vnpy/api/ctp
CTPAPI_TD_LIBRARY
linked by target "vnctptd" in directory /home/john/PYTHON/vnpy19/vnpy/api/ctp

-- Configuring incomplete, errors occurred!
See also "/home/john/PYTHON/vnpy19/vnpy/api/ctp/build/CMakeFiles/CMakeOutput.log".
See also "/home/john/PYTHON/vnpy19/vnpy/api/ctp/build/CMakeFiles/CMakeError.log".

如果不理会,直接pycharm执行example下面的run
报错:
File "/home/john/PYTHON/vnpy19/vnpy/api/ctp/__init__.py", line 4, in <module>
from .vnctpmd import MdApi
ImportError: libthostmduserapi.so: cannot open shared object file: No such file or directory

创建目录:ctpapi/x64_linux(vnpy19/vnpy/api/ctp/下)
1,将ctpapi下的文件复制一份,到子目录x64_linux中
2,并将thostmduserapi_se.so文件名改为libthostmduserapi_se.so,thosttraderapi_se.so改为libthosttraderapi_se.so
3,此时就可以编译了,去vnpy根路径执行bash install.sh,将其他接口全部yes安装
4,vnpy/api/ctp目录下会生成vnctpmd.so 和vnctptd.so文件。
ctpGateway模块有导入这两个模块。所以将这两个copy到ctpGateway文件夹下
同时ctptestGateway也放一份,否则启动ctptest时也会报错
同时,anaconda里面的相应路径也需要放一份。
此时直接执行VnTrader下的run成功启动界面
(在终端如果无法启动,可以重新安装试试,或者把vnpy项目整体copy到anaconda下的对应sitepack相应目录,之后在重新安装)

远程主机合并最新192穿透测试

1,拉取最新版本挪,git checkout yuan_vnpy19
删除旧版分支git branch -d yuan
2,下拉代码,安装
git pull
bash install.sh
3,执行:cd examples/VnTrader/;python run.py
报错:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
Traceback (most recent call last):
File "run.py", line 28, in <module>
from vnpy.trader.gateway import (ibGateway, huobiGateway, okexfGateway, okexGateway, ccxtGateway,
File "/root/anaconda3/envs/vnpy27/lib/python2.7/site-packages/vnpy-1.9.2-py2.7.egg/vnpy/trader/gateway/ctptestGateway/__init__.py", line 5, in <module>
from .ctptestGateway import CtptestGateway
File "/root/anaconda3/envs/vnpy27/lib/python2.7/site-packages/vnpy-1.9.2-py2.7.egg/vnpy/trader/gateway/ctptestGateway/ctptestGateway.py", line 16, in <module>
from vnctpmd import MdApi
ImportError: libboost_python-py27.so.1.65.1: cannot open shared object file: No such file or directory


ls 编译前后路径是否有文件缺失
ls -alh ~/PYTHON/vnpy19/vnpy/trader/gateway/ctptestGateway
ls -alh /root/anaconda3/envs/vnpy27/lib/python2.7/site-packages/vnpy-1.9.2-py2.7.egg/vnpy/trader/gateway/ctptestGateway/
无缺失(pyc无关)

考虑到本机是有一步so的拷贝操作,(未使用原有的,使用编译后生成so复制过来)
cp ../../vnpy/api/ctp/*.so ../../vnpy/trader/gateway/ctptestGateway/
cp ../../vnpy/api/ctp/*.so ../../vnpy/trader/gateway/ctpGateway/
依然报同样的错误

尝试查找文件,软连接
find / -name libboost_python-py27.so.1.65.1
返回:空
find / -name libboost_python-py27.so
返回:/usr/lib/x86_64-linux-gnu/libboost_python-py27.so
本机目录同ananconda路径下也没有libboost_python-py27.so.1.65.1这个,
司马当成活马医,试试软连接
ln -s /usr/lib/x86_64-linux-gnu/libboost_python-py27.so /root/anaconda3/envs/vnpy27/lib/python2.7/site-packages/vnpy-1.9.2-py2.7.egg/vnpy/trader/gateway/ctptestGateway/libboost_python-py27.so.1.65.1
试试python run.py,依然不行
删除软连接 rm libboost_python-py27.so.1.65.1

添加上交conda源重新执行安装脚本
不行

源代码安装libboost
参考地址:https://stackoverflow.com/questions/46934760/importerror-libboost-python-so-1-65-1-cannot-open-shared-object-file-no-such

wget https://dl.bintray.com/boostorg/release/1.65.1/source/boost_1_65_1.tar.gz \
&& tar zxf boost_1_65_1.tar.gz \
&& cd boost_1_65_1 \
&& ./bootstrap.sh --with-libraries=python --with-python=python2.7 \
&& ./b2 install

卸载手工安装libboost,集成方式重新安装
sudo apt-get autoremove libboost-dev
搜索之前自己笔记:sudo apt-get install libboost-all-dev
执行vnpy的install.sh安装脚本
报错
CMake Error at /usr/share/cmake-3.5/Modules/FindBoost.cmake:1677 (message):
Unable to find the requested Boost libraries.
Boost version: 1.65.1
Boost include path: /usr/local/include
Could not find the following Boost libraries:
boost_thread
boost_date_time
boost_system

搜索下其他方案
地址:https://stackoverflow.com/questions/24173330/cmake-is-not-able-to-find-boost-libraries
sudo apt-get install cmake libblkid-dev e2fslibs-dev libboost-all-dev libaudit-dev
不行,全部下卸载掉

猜测法,阅读报错部分
Boost include path: /usr/local/include
Could not find the following Boost libraries:

boost_thread
boost_date_time
boost_system
boost_chrono

Some (but not all) of the required Boost libraries were found. You may
need to install these additional Boost libraries. Alternatively, set
BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
to the location of Boost.
Call Stack (most recent call first):
CMakeLists.txt:83 (find_package)
所以:直接信息Boost include path: /usr/local/include,配置错了
或者BOOST_LIBRARYDIR,BOOST_ROOT配置错了或为配置
在安装libboost-all-dev的日志其实有libboost_thread等这一坨信息,但是未找到
尝试1,
export Boost_INCLUDE_DIR=/usr/local/include/boost/
不行。
尝试2,find / -name libboost_th*
/usr/lib/x86_64-linux-gnu/libboost_thread.a
/usr/lib/x86_64-linux-gnu/libboost_thread.so.1.58.0
/usr/lib/x86_64-linux-gnu/libboost_thread.so
export BOOST_LIBRARYDIR=/usr/lib/x86_64-linux-gnu/
ok了。
这个网上查询到资料和自己不一致,很大可能是自己root登录,软件默认位置和他人大多数不同,导致按照他人方案不可性。

补充:彻底卸载1.58版本(避免影响其他版本安装)
sudo apt-get autoremove libboost1.58-dev

卸载1.65版本
/usr/local/lib$ sudo rm -rf libboost_*
/usr/local/include$ sudo rm -rf boost/

比对本机ok的环境和服务器有问题环境
sudo find / -name 'libboost_python-py27*'
本机:
/usr/lib/x86_64-linux-gnu/libboost_python-py27.a
/usr/lib/x86_64-linux-gnu/libboost_python-py27.so
/usr/lib/x86_64-linux-gnu/libboost_python-py27.so.1.65.1

服务器
/usr/lib/x86_64-linux-gnu/libboost_python-py27.a
/usr/lib/x86_64-linux-gnu/libboost_python-py27.so
/usr/lib/x86_64-linux-gnu/libboost_python-py27.so.1.58.0

可见主要问题时版本不对。
本机搜索:sudo apt search libboost1.65,有结果
服务器搜索:sudo apt search libboost1.65,无结果
问题比较明显了,apt源不对,将服务器源同步到和本机一致。之后用aptget服务器安装1.65
服务器安装:sudo apt-get install libboost1.65-dev
依然报错。

服务器搜索:sudo apt search libboost-all*
正在排序... 完成
全文搜索... 完成
libboost-all-dev/bionic,bionic 1.65.1.0ubuntu1 amd64
Boost C++ Libraries development files (ALL) (default version)
可见,应该安装libboost-all-dev,而不仅libboost1.65

尝试安装libboost-all-dev。
先卸载libboost1.65在安装libboost-all-dev

安装websocker4.4

下载:https://github.com/huobiapi/Futures-Python-demo/tree/master/Websocket-Python3-demo
安装:pip install websocket_client-0.44.0-py2.py3-none-any.whl

安装hyperopt

pip install hyperopt

安装sklearn

pip install sklearn

multiprocess

pip install multiprocess

安装h5压缩格式的支持

1
pip install --upgrade tables

vnpy2.0版本(20190523)

由于1.9的接口很多无法使用,所以实盘只能升级到2.0了

1,创建环境

conda create -n vnpy37 python=3.7
报错 CondaHTTPError: HTTP 404 NOT FOUND for url

1
2
3
使用上交源
- https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main/
- https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/free/

2,执行bashinstall

切换到git pull的源代码路径
报错:ModuleNotFoundError: No module named ‘vnpy.api.ctp.vnctpmd’

1
2
3
4
5
6
7
8
9
10
11
12
13
ModuleNotFoundError: No module named 'vnpy.api.ctp.vnctpmd'
参考:https://github.com/vnpy/vnpy/issues/1686
To add '.so' on Linux
https://github.com/vnpy/vnpy/pull/1693
就是说需要执行python setup.py build ;python setup.py install

自己和1.9比对摸索看出门道了
build里面的lib中找下,build/lib/vnpy/api/ctp,下面有个vnctpmd.so或者vnctptd.so的copy到vnpy/api/ctp路径下下即可
注意1,build里面的lib,这个可能有多个,lib.linuxx64,lib.temp,等,找一个对应路径有so的,我这里有build下面有4个lib开始文件夹,但仅有一个相应位置有so文件,其他都是干扰项
注意2,vnctpmd.so和vnctptd.so的名字可能不完全一样,比如vnctptd.xxxxxxxx.so,vnctpmd.xxxxxxx.so等,只要vnctpmd开头so结尾就算满足条件了。
注意3,如果都没有,满足条件so,则编译生成下
项目根路径/setup.py里面有编译脚本
执行:python setup.py build即可。

3,次日启动发现启动又不行了,pycharm也不行

pycharm中启动
报错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  File "/home/john/PYTHON/vnpy20/vnpy/event/eventEngine.py", line 11, in <module>
from qtpy.QtCore import QTimer
ModuleNotFoundError: No module named 'qtpy'

安装执行:
conda install pyqt
conda install qtpy
执行run.py

新报错
Traceback (most recent call last):
File "/home/john/PYTHON/vnpy20/run.py", line 2, in <module>
from vnpy.trader.engine import MainEngine
ModuleNotFoundError: No module named 'vnpy.trader.engine'
同时pycharm提示一堆缺少没有安装的。

干脆重新安装bash install.sh吧。
额,发现git的分支搞错了,分支1.9了,应该时yuan_vnpy20分支
切换回去,好了

4,pycharm提示缺少psycopg2

安装:conda install psycopg2

5,使用接口ctptest时报错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
ModuleNotFoundError: No module named 'vnpy.gateway.ctptest.vnctpmd'  
结局:进入vnpy/api/ctp,里面2个so,
vnctpmd.cpython-37m-x86_64-linux-gnu.so
vnctptd.cpython-37m-x86_64-linux-gnu.so
以及:
build/lib/vnpy/trader/gateway/ctptestGateway的2个so(需要改名加前缀lib)拷贝过来
libthostmduserapi_se.so
libthosttraderapi_se.so
copy到ctptestgateway/下面

启动:报错
此时连接均成功,但是新报错
交易服务器授权验证失败,代码:63,信息:CTP:客户端认证失败

同时注意,anaconda下面的vnpy项目可能也要复制过去,我这里貌似不用

6,使用simnow登录

第一种情况:报错3,不合法的登录
第二种情况:/sys/firmware/dmi/tables/DMI: Permission denied
二者应该等价,应为我什么都没改,都是没取的系统信息导致的

7,在云主机上的安装

1,创建环境,
2,bash install.sh(在安装主脚本时,建议先执行python setup.py build && python setup.py install可以避免很多后续问题)
有一堆报错,删除环境重新按照步骤安装依然如此,暂时不管
3,
conda install pyqt
conda install qtpy
pip install pyqtgraph
pip Install sklearn
4,启动run.py,ok

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×