vn.py量化社区
By Traders, For Traders.
Member
avatar
加入于:
帖子: 1
声望: 1

有些图片不好弄,可以去这里找原文看,排版好一点
1.更新源
刚刚安装好的Ubuntu18.04没有vim,为了后面修改文件,先安装vim
sudo apt-get install vim
在ubuntu 18.04中,按照之前的博文《linux常用命令》修改成源阿里云的源。我们把代码粘贴在这里:

备份配置文件

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

打开文件

sudo vim /etc/apt/sources.list

重开终端,查看版本代号

lsb_release -c

#Ubuntu 12.04 (LTS)代号为precise
#Ubuntu 14.04 (LTS)代号为trusty
#Ubuntu 15.04 代号为vivid
#Ubuntu 15.10 代号为wily
#Ubuntu 16.04 (LTS)代号为xenial
#Ubuntu 18.04 代号为bionic

更新文件如下

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

更新文件列表

sudo apt-get update

2.安装Miniconda3

build-essential不能少,apt-get安装之。
sudo apt-get install build-essential
之后安装Python运行环境,Miniconda是轻量化的python包管理器。
安装Miniconda,获得Python 3.7运行环境(为vnpy2.0.9匹配)。具体方法是去官网下载Miniconda3-latest-Linux-x86_64.sh,在终端直接bash即可。
bash Miniconda3-latest-Linux-x86_64.sh
最后一步记得选yes

3.安装postgresql包

安装过程vnpy之前,需要一个叫postgresql的包,少不了,网上有用源码安装或者用yum安装的,都不好。源码太麻烦,yum容易跟apt抢戏。

最好的是下面的方法:
sudo vim /etc/apt/sources.list.d/pgdg.list

加入如下内容

deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main

最后

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
还要增加一个包libpq-dev
sudo apt-get install libpq-dev
sudo vim /etc/apt/sources.list.d/pgdg.list

加入如下内容

deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main

最后

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
还要增加一个包libpq-dev
sudo apt-get install libpq-dev

4.安装vnpy2.0.9
下载vnpy2.0.9,解压。切换到vnpy2.0.9目录下,bash文件install.sh安装。sudo执行时会重置环境变量,导致miniconda在普通用户的.bashrc的设置失效。具体地可以从/etc/sudoers文件里的env_reset中得到佐证。要解决bash与sudo命令的冲突,可以进行如下命令进行安装:
sudo PATH=/home/han/miniconda3/bin:$PATH bash install.sh

*可选操作
即使如此,还是会有个warning:WARNING: The directory '/home/zhex/.cache/pip/http' or its parent directory is not owned by the curr
WARNING: The directory '/home/zhex/.cache/pip/http' or its parent directory is not owned by the curr
很容易理解,root并不拥有普通用户的所有文件,所以一些事情就没做,解决办法:
sudo chown -R root /home/han/.cache/pip/
sudo chown -R root /home/han/.cache/pip/http/
解决了warning。

5.VNPY运行
切换到vnpy-2.0.9的examples/vn_trader目录下,修改run.py注释掉四行,

from vnpy.gateway.femas import FemasGateway
from vnpy.app.option_master import OptionMasterApp
main_engine.add_gateway(FemasGateway)
main_engine.add_app(OptionMasterApp)
最后下在该目录下
python run.py

Administrator
avatar
加入于:
帖子: 4033
声望: 221

给你加个精华!

Member
avatar
加入于:
帖子: 1
声望: 0

感谢大佬,专门注册个账号来顶你。windows上很快弄好,ubuntu卡了一天了都没弄好,按照你的方法终于搞定了。

© 2015-2019 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号-3