一、安装篇
需要用到的软件工具Anaconda\Tushare\Jupyter Notebook,为方便以后使用不再配置建议使用Docker安装
1.安装Docker-ce
sudo apt-get remove docker docker-engine docker.io
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
ubuntu18.04增加源及公钥
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add
deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic stable
sudo apt-get update
sudo apt-get install docker-ce
2.Docker内安装Anaconda\Jupyter Notebook
docker pull centos:latest
docker run -it -p 宿主机端口:容器应用端口 centos:latest /bin/bash
# 在容器内进行
参考数据科学环境搭建的两个网站
https://blog.patricktriest.com/analyzing-cryptocurrencies-python/
http://www.360doc.com/content/17/1212/02/48630098_712275639.shtml(翻译)
yum install wget
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.3.1-Linux-x86_64.sh
bash Anaconda3-5.3.1-Linux-x86_64.sh
source ~/.bashrc
conda -V
conda upgrade -n base conda
conda install jupyter notebook
conda install ipython
jupyter notebook --generate-config
# ipython 进入python shell交互
In [1]: from notebook.auth import passwd
In [2]: passwd()
vi ~/.jupyter/jupyter_notebook_config.py
c.NotebookApp.ip='*' # 设置所有ip皆可访问
c.NotebookApp.password = u'sha1:67c9e60b771089e11aed' #ipython上面生成的哈希值'
c.NotebookApp.open_browser = False # 禁止自动打开浏览器
c.NotebookApp.port = 8080 #指定一个端口
c.NotebookApp.allow_password_change=False
# 启动jupyter notebook
jupyter notebook --no-browser --allow-root
安装jupyterlab同理
conda install -c conda-forge jupyter #一般不需要anaconda自带
conda install -c conda-forge jupyterlab
安装插件
conda install -c conda-forge nodejs
conda upgrade -n base nodejs #一定要升级不然装插件会出意外
具体插件参考https://zhuanlan.zhihu.com/p/101070029/
pip修改国内源添加-i https://pypi.tuna.tsinghua.edu.cn/simple
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple ipdb
conda修改为国内源
conda config --set show_channel_urls yes
nano .condarc
channels:
- defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
3.安装Tushare
yum groupinstall "Development Tools"
yum install gcc libffi-devel python-devel openssl-devel
pip install TA-Lib
如果安装不了需要自己编译
wget https://downloads.sourceforge.net/project/ta-lib/ta-lib/0.4.0/ta-lib-0.4.0-src.tar.gz?r=https%3A%2F%2Fsourceforge.net%2Fprojects%2Fta-lib%2Ffiles%2Fta-lib%2F0.4.0%2F&ts=1509527628&use_mirror=nchc
#tar -xvf ta-lib-0.4.0-src.tar.gz
#cd ta-lib
#./configure
#make && make install
#echo "/usr/local/lib" >> /etc/ld.so.conf
#ldconfig
pip install TA-Lib
结果还是不行
conda install -c https://conda.anaconda.org/quantopian ta-lib
pip install tushare
安装graphlab用于图象处理(目前只支持python2.7)
参考网站
https://turi.com/download/install-graphlab-create.html?email=tangd86%40gmail.com&key=1825-54EB-DD4E-61BC-4ABB-0689-AFF7-F45A
# Create a new conda environment with Python 2.7.x
conda create -n gl-env python=2.7
# Activate the conda environment
source activate gl-env
# Ensure pip is updated to the latest version
conda update pip
pip install --upgrade --no-cache-dir https://get.graphlab.com/GraphLab-Create/2.1/tangd86@gmail.com/1825-54EB-DD4E-61BC-4ABB-0689-AFF7-F45A/GraphLab-Create-License.tar.gz
import graphlab时报错,在终端内gl-env环境运行python2.7
[gl-env] python
>>> import graphlab
>>> graphlab.get_dependencies()
根据提示修改get_dependencies() 的源码,源码位置python->site-packages->graphlab->dependencies.py
(xzarchive_file, xzheaders) = urllib.urlretrieve('http://tukaani.org/xz/xz-5.2.1-windows.zip',reporthook = cbk)
(dllarchive_file, dllheaders) = urllib.urlretrieve('http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-gcc-libs-5.1.0-1-any.pkg.tar.xz',reporthook = cbk)
复制这两个网址下载这两个文件,然后在 dependencies.py 中注释掉这两句话分别改成:
xzarchive_file = '文件路径\\xz-5.2.1-windows.zip'
dllarchive_file = '文件路径\\mingw-w64-x86_64-gcc-libs-5.1.0-1-any.pkg.tar.xz'
# docker容器转镜像完成配置
sudo docker commit -m "镜像说明" -a “你的用户名" 容器id 镜像名:标签
Jupyter 插件
## 安装 ipywidgets, 会同时安装 widgetsnbextension
conda install ipywidgets
## 安装插件更丰富的jupyter_contrib_nbextensions
## Autopep8 插件需要额外安装库
conda install -c conda-forge jupyter_contrib_nbextensions
conda install autopep8 jupyter_contrib_nbextensions
## 安装插件管理器 jupyter_nbextensions_configurator
conda install -c conda-forge jupyter_nbextensions_configurator
折叠的标题Collapsible headings
通知机制Notify
折叠代码Code folding
轻轻一击就能获得简洁代码Autopep8
创建的所有变量的属性variable inspector
使用Tshare先要注册获得TOKEN,链接https://tushare.pro/register?reg=292031
import tushare as ts
ts.set_token(065ae2706ad962f80030857336b65877bc579d9763a919b9018d2182)
pro = ts.pro_api()