Python开发股票量化系统从入门到放弃(二)

Python开发股票量化系统从入门到放弃(二),第1张

本期目录

  • 二、开发准备

  • 1. 确定开发目标
  • 2. 确认系统结构
  • 2. 选择开发语言
  • 3. 选择开发环境
  • 4. 选择数据库
  • 5. 选择界面组件
    • - 安装PyQt5-tools,失败
    • - 为什么安装PyQt失败
    • - 重新安装PyQt5-tools,成功
    • - Vscode配置PyQt5
  • 6. 结论


二、开发准备 1. 确定开发目标

接前言,已经确认开发一个个人阉割版的股票量化系统,那么需要确认一些问题:

  • 系统结构
  • 开发语言
  • 开发环境
  • 数据库
  • 开发界面
2. 确认系统结构

我知道的系统结构,无外乎C/S、B/S、存粹的C。


我知道一定还有其它系统结构,我是小白我怕谁

首先尽可能简单,而且只有一个用户,那么B/S结构没有必要。


那么PC端开发,需要一个服务端吗?

需要吗?不需要吗?我就是研究一下,真的需要吗?

说实话,还真的需要一个服务端,如果:

  • 需要程序定时运行某些功能
  • 脏活累活得有人来做,服务端来做正合适
  • C/S毕竟比较得瑟

所以,系统结构目标是C/S结构,先实现全部功能,然后再拆分客户端和服务端。


2. 选择开发语言

开发C/S结构,很多开发语言都可以选择,无外乎:

  • C++/C#,大概率需要Visual Studio支持,只是开发一个小功能,没必要,pass
  • Java,好像也得JDK支持,还不够麻烦的
  • PHP,是个选择
  • Python,也是个选择

看了一下PHP和Python比较,最后选择Python,具体理由就是没有理由。




最新版Python 3.10.4走起。


3. 选择开发环境

10个超好用的【Python集成开发环境】推荐

推荐一:PyCharm
推荐二:Vim
推荐三:Eclipse with PyDev
推荐四:Sublime Text
推荐五:Visual Studio Code
推荐六: Atom
推荐七: Emacs
推荐八:Spyder
推荐九:Thonny
推荐十: Wing

最后选择 Visual Studio Code,没有理由。




下载,安装。


VSCode安装Python拓展包,网上到处都有

4. 选择数据库

沪深交易的A股有4500多支,记录从2010年到今天,大约12年,每年交易200天,估算数据量是:

450012200 = 10,800,000条

数据大约是1千万数量级,不大不小。


数据存储无外乎两种方式:

  • 文件存储
  • 数据库存储

文件存储存成一个文件不合理,所以需要一个股票一个文件,不利于查找定位,pass。


那就只能使用数据库存储,几种选择:

  • Python自带的Sqlite3
  • 安装MySQL等SQL软件
  • 安装NoSQL等NOSQL软件

查了一下Sqlite的性能,支持几千万条记录,数据库性能还可以,就它了。


选择Sqlite自己给自己挖了好几个坑

还得在VSCode里面安装Sqlite扩展包

5. 选择界面组件

潜意思里面,软件总需要一个软件界面。


Tkinter是python自带的gui界面工具,做出来的东西感觉吧,我还是试试别的吧。


最后选择QT5。


按照网上的安装PyQT教程,开始安装。


- 安装PyQt5-tools,失败

首先安装PyQt5

pip3 install PyQt5

Defaulting to user installation because normal site-packages is not writeable
Collecting PyQt5
  Using cached PyQt5-5.15.6-cp36-abi3-win_amd64.whl (6.7 MB)
Collecting PyQt5-Qt5>=5.15.2
  Using cached PyQt5_Qt5-5.15.2-py3-none-win_amd64.whl (50.1 MB)
Collecting PyQt5-sip<13,>=12.8
  Downloading PyQt5_sip-12.9.1-cp310-cp310-win_amd64.whl (77 kB)
     ---------------------------------------- 77.7/77.7 KB 392.1 kB/s eta 0:00:00
Installing collected packages: PyQt5-Qt5, PyQt5-sip, PyQt5
  WARNING: The scripts pylupdate5.exe, pyrcc5.exe and pyuic5.exe are installed in 'C:\Users\huzc\AppData\Roaming\Python\Python310\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed PyQt5-5.15.6 PyQt5-Qt5-5.15.2 PyQt5-sip-12.9.1

成功了!(成功不是应该的吗!?)

然后安装PyQt5-tools

pip install PyQt5-tools

Defaulting to user installation because normal site-packages is not writeable
Collecting PyQt5-tools
  Using cached pyqt5_tools-5.15.4.3.2-py3-none-any.whl (29 kB)
Collecting python-dotenv
  Downloading python_dotenv-0.20.0-py3-none-any.whl (17 kB)
Collecting pyqt5==5.15.4
  Downloading PyQt5-5.15.4.tar.gz (3.3 MB)
     ---------------------------------------- 3.3/3.3 MB 655.7 kB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error
  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [29 lines of output]
      Traceback (most recent call last):
        File "C:\Program Files\Python310\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 156, in prepare_metadata_for_build_wheel
          hook = backend.prepare_metadata_for_build_wheel
      AttributeError: module 'sipbuild.api' has no attribute 'prepare_metadata_for_build_wheel'

      During handling of the above exception, another exception occurred:
      Traceback (most recent call last):
        File "C:\Program Files\Python310\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 363, in 
          main()
        File "C:\Program Files\Python310\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 345, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "C:\Program Files\Python310\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 160, in prepare_metadata_for_build_wheel
          whl_basename = backend.build_wheel(metadata_directory, config_settings)
        File "C:\Users\huzc\AppData\Local\Temp\pip-build-env-4v39tqor\overlay\Lib\site-packages\sipbuild\api.py", line 51, in build_wheel
          project = AbstractProject.bootstrap('pep517')
        File "C:\Users\huzc\AppData\Local\Temp\pip-build-env-4v39tqor\overlay\Lib\site-packages\sipbuild\abstract_project.py", line 83, in bootstrap
          project.setup(pyproject, tool, tool_description)
        File "C:\Users\huzc\AppData\Local\Temp\pip-build-env-4v39tqor\overlay\Lib\site-packages\sipbuild\project.py", line 594, in setup
          self.apply_user_defaults(tool)
        File "C:\Users\huzc\AppData\Local\Temp\pip-install-ntabtr7u\pyqt5_c299f0f11fb446cea953108a4de227fd\project.py", line 63, in apply_user_defaults
          super().apply_user_defaults(tool)
        File "C:\Users\huzc\AppData\Local\Temp\pip-build-env-4v39tqor\overlay\Lib\site-packages\pyqtbuild\project.py", line 70, in apply_user_defaults
          super().apply_user_defaults(tool)
        File "C:\Users\huzc\AppData\Local\Temp\pip-build-env-4v39tqor\overlay\Lib\site-packages\sipbuild\project.py", line 241, in apply_user_defaults
          self.builder.apply_user_defaults(tool)
        File "C:\Users\huzc\AppData\Local\Temp\pip-build-env-4v39tqor\overlay\Lib\site-packages\pyqtbuild\builder.py", line 67, in apply_user_defaults
          raise PyProjectOptionException('qmake',
      sipbuild.pyproject.PyProjectOptionException
      [end of output]

出错了!

- 为什么安装PyQt失败

找到错误代码,AttributeError: module ‘sipbuild.api’ has no attribute ‘prepare_metadata_for_build_wheel’ ,在网上查找。


首选答案是

https://stackoverflow.com/questions/65447314/attributeerror-module-sipbuild-api-has-no-attribute-prepare-metadata-for-bui

看了一下,没什么用。


自己找。


去PyQt5上看看


版本没错啊。


等等,Released: Mar 10,2021,2021年3月发行。


看看Python呢


Python 3.10 开始发行时间2021年10月。


有没有可能QT5现在不支持Python3.10?!

- 重新安装PyQt5-tools,成功

说干就干,卸载Python 3.10,安装Python 3.9.10

第一次放弃!

安装后运行

python

Python 3.9.10 (tags/v3.9.10:f2f3f53, Jan 17 2022, 15:14:21) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

pip install PyQt5

Collecting PyQt5
  Using cached PyQt5-5.15.6-cp36-abi3-win_amd64.whl (6.7 MB)
Collecting PyQt5-Qt5>=5.15.2
  Using cached PyQt5_Qt5-5.15.2-py3-none-win_amd64.whl (50.1 MB)
Collecting PyQt5-sip<13,>=12.8
  Using cached PyQt5_sip-12.9.1-cp39-cp39-win_amd64.whl (77 kB)
Installing collected packages: PyQt5-sip, PyQt5-Qt5, PyQt5
Successfully installed PyQt5-5.15.6 PyQt5-Qt5-5.15.2 PyQt5-sip-12.9.1
WARNING: You are using pip version 21.2.4; however, version 22.0.4 is available.
You should consider upgrading via the 'D:\Python\Python39\python.exe -m pip install --upgrade pip' command.

python.exe -m pip install --upgrade pip

Requirement already satisfied: pip in d:\python\python39\lib\site-packages (21.2.4)
Collecting pip
  Using cached pip-22.0.4-py3-none-any.whl (2.1 MB)
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 21.2.4
    Uninstalling pip-21.2.4:
      Successfully uninstalled pip-21.2.4
Successfully installed pip-22.0.4

pip install PyQt5-tools

Collecting PyQt5-tools
  Using cached pyqt5_tools-5.15.4.3.2-py3-none-any.whl (29 kB)
Collecting pyqt5==5.15.4
  Using cached PyQt5-5.15.4-cp36.cp37.cp38.cp39-none-win_amd64.whl (6.8 MB)
Collecting click
  Downloading click-8.1.2-py3-none-any.whl (96 kB)
     ---------------------------------------- 96.6/96.6 KB 461.7 kB/s eta 0:00:00
Collecting python-dotenv
  Using cached python_dotenv-0.20.0-py3-none-any.whl (17 kB)
Collecting pyqt5-plugins<5.15.4.3,>=5.15.4.2.2
  Using cached pyqt5_plugins-5.15.4.2.2-cp39-cp39-win_amd64.whl (67 kB)
Requirement already satisfied: PyQt5-sip<13,>=12.8 in d:\python\python39\lib\site-packages (from pyqt5==5.15.4->PyQt5-tools) (12.9.1)
Requirement already satisfied: PyQt5-Qt5>=5.15 in d:\python\python39\lib\site-packages (from pyqt5==5.15.4->PyQt5-tools) (5.15.2)
Collecting qt5-tools<5.15.2.2,>=5.15.2.1.2
  Using cached qt5_tools-5.15.2.1.2-py3-none-any.whl (13 kB)
Collecting colorama
  Using cached colorama-0.4.4-py2.py3-none-any.whl (16 kB)
Collecting click
  Using cached click-7.1.2-py2.py3-none-any.whl (82 kB)
Collecting qt5-applications<5.15.2.3,>=5.15.2.2.2
  Using cached qt5_applications-5.15.2.2.2-py3-none-win_amd64.whl (60.9 MB)
Installing collected packages: qt5-applications, python-dotenv, pyqt5, click, qt5-tools, pyqt5-plugins, PyQt5-tools
  Attempting uninstall: pyqt5
    Found existing installation: PyQt5 5.15.6
    Uninstalling PyQt5-5.15.6:
      Successfully uninstalled PyQt5-5.15.6
Successfully installed PyQt5-tools-5.15.4.3.2 click-7.1.2 pyqt5-5.15.4 pyqt5-plugins-5.15.4.2.2 python-dotenv-0.20.0 qt5-applications-5.15.2.2.2 qt5-tools-5.15.2.1.2

安装成功

- Vscode配置PyQt5

一如既往的,安装PYQT Integration扩展包

设置参数

鼠标右键

里面有 PYQT:New Form,点开试试

应该能运行,以后再用吧。


其实,我第一次配置QTdesigner地址错误,开始多了一个空格

6. 结论

终于开发环境配置完了,一句话,该怂就怂。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/568990.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-09
下一篇 2022-04-09

发表评论

登录后才能评论

评论列表(0条)

保存