在anaconda中安装国产量化环境vn studio (同时安装vn station 及 vnpy)
项目场景:
在anaconda中搭建vn station环境,但是在CTA中不能引入安装的tensorflow
问题描述
想在ancaconda中安装一个环境,并且在vn station中使用tensorflow torch,通过anaconda prompt 进入环境能正常使用tensorflow 和torch ,能正常导入
我在boll_chanal_strategy.py中引入tensorflow,并且测试,结果不能使用gpu:
D:\Anaconda3\envs\veighna_studio\lib\site-packages\vnpy_ctastrategy\strategies\boll_channel_strategy.py:
import tensorflow as tf
print(tf.__version__)
print('可以使用gpu:',tf.config.list_physical_devices('GPU'))
import sys
print("python执行器位置:",sys.executable)
但是在点击启动vn station --> 交易 --> 启动–> 点击回测 后,在veighna station 中报错:
2023-12-12 21:35:31 --------------------------------------------------
2023-12-12 21:35:31 VeighNa Trader进程启动
2023-12-12 21:35:33 没有配置要使用的数据服务,请修改全局配置中的datafeed相关内容
2023-12-12 21:35:47 2.10.0
2023-12-12 21:35:47 2023-12-12 21:35:47.685061: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cublas64_11.dll'; dlerror: cublas64_11.dll not found
2023-12-12 21:35:47 2023-12-12 21:35:47.685957: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cublasLt64_11.dll'; dlerror: cublasLt64_11.dll not found
2023-12-12 21:35:47 2023-12-12 21:35:47.686903: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cufft64_10.dll'; dlerror: cufft64_10.dll not found
2023-12-12 21:35:47 2023-12-12 21:35:47.826458: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cusparse64_11.dll'; dlerror: cusparse64_11.dll not found
2023-12-12 21:35:47 2023-12-12 21:35:47.827418: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudnn64_8.dll'; dlerror: cudnn64_8.dll not found
2023-12-12 21:35:47.827795: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1934] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
可以使用gpu: []
python执行器位置: D:\Anaconda3\envs\veighna_studio\python.exe
2.10.0
可以使用gpu: []
python执行器位置: D:\Anaconda3\envs\veighna_studio\python.exe
下面是我的安装步骤:
-
在
D:\Anaconda3\envs目录下新建目录veighna_studio -
在vn官网 下载社区版3.9.0 VeighNa量化社区 - 你的开源社区量化交易平台 (vnpy.com)
点击安装时选择目录:
D:\Anaconda3\envs\veighna_studio安装好后桌面会有图标
安装好后系统的环境变量中可能会有添加了该目录,可以删除一下
比如:
C:\Program Files\NVIDIA Corporation\Nsight Compute 2023.3.1\
-
将目录
D:\Anaconda3\envs\veighna_studio添加为anaconda环境:conda create --prefix="D:\Anaconda3\envs\veighna_studio" python=3.10.9我使用的是 anaconda prompt 执行
如果执行报错json.decoder.JSONDecodeError: :输入命令
conda config --show-sources, 查出.condarc文件路径, 删除该文件,重新执行创建环境的命令python的版本可以执行
D:\Anaconda3\envs\veighna_studio\python命令查看版本 -
安装Tensorflow
版本对应关系:Build from source on Windows | TensorFlow (google.cn)
pip install tensorflow-gpu==2.10.0 -i https://pypi.mirrors.ustc.edu.cn/simple/ conda install cudatoolkit=11.1.1 cudnn=8.1.0 conda install cudatoolkit=11.2 cudnn=8.1.0 conda install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0安装cudatoolkit=11.2和cudnn=8.1-CSDN博客
Build from source on Windows | TensorFlow (google.cn)
测试安装是否成功(命令行中测试)
import tensorflow as tf print(tf.__version__) print('可以使用gpu:',tf.config.list_physical_devices('GPU')) -
安装pytorch
在anaconda环境中使用conda命令安装cuda、cudnn、tensorflow(-gpu)、pytorch_conda安装cuda-CSDN博客
安装命令 :Previous PyTorch Versions | PyTorch
conda install pytorch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 pytorch-cuda=12.1 -c pytorch -c nvidia # 下面这条命令实测可行 命令来源:https://pytorch.org/ pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121在anaconda环境中使用conda命令安装cuda、cudnn、tensorflow(-gpu)、pytorch_conda安装cuda-CSDN博客
Previous PyTorch Versions | PyTorch
测试是否安装成功
import torch print(torch.__version__) print(torch.cuda.is_available())
原因分析:
求回复~~~
解决方案:
在anaconda 中打开命令行,进入创建的虚拟环境 vnpy_ctastrategy 执行命令行:
pythonw.exe -m veighna_station
即可正常使用该环境,出现问题的原因大概是因为没有开启建设的环境
可以目测的,更好的解决方案(未实践):
直接在anaconda的外目录 (base环境)中安装vn studio即可解决
更多推荐




所有评论(0)