安装指南
本指南将帮助您在不同平台上安装和配置 TechKit。根据您的使用场景选择合适的安装方式。
Python 安装
基本安装
Python 版本是 TechKit 最常用的版本,特别适合数据分析和研究场景。
pip install techkit
系统要求
Python 版本: 3.10 或更高版本
依赖库: NumPy 1.21 或更高版本(会自动安装)
操作系统:
Linux (x86_64, aarch64)
macOS (x86_64, arm64)
Windows (AMD64)
验证安装
安装完成后,可以通过以下方式验证:
import techkit as tk
import numpy as np
# 测试基本功能
sma = tk.SMA(period=20)
prices = np.array([100.0, 101.0, 102.0, 103.0, 104.0])
result = sma.calculate(prices)
print("安装成功!TechKit 版本:", tk.__version__)
print("SMA 计算结果:", result)
常见问题
Q: 安装时出现编译错误?
A: TechKit Python 包提供了预编译的二进制包(wheel),大多数情况下不需要编译。如果遇到问题:
确保 Python 版本 >= 3.10
确保 pip 是最新版本:
pip install --upgrade pip尝试使用
pip install techkit --no-cache-dir
Q: 如何升级到最新版本?
A: pip install --upgrade techkit
Q: 支持 Python 3.9 吗?
A: 不支持。TechKit 需要 Python 3.10+ 的新特性。
JavaScript / Node.js 安装
TechKit 提供两个 Node.js 包,根据您的需求选择:
techkit (核心版) - 推荐大多数用户
npm install techkit
# 或
yarn add techkit
# 或
pnpm add techkit
特点:
包含 158+ 个核心指标(TA-Lib 兼容)
体积小(WASM ~200KB)
支持 Node.js 和浏览器
自动选择最优后端(Native 或 WASM)
适用场景: 大多数应用,需要常用技术指标
techkit-full (完整版) - 需要完整功能
npm install techkit-full
# 或
yarn add techkit-full
# 或
pnpm add techkit-full
特点:
包含所有 189 个指标
包含高级分析功能(风险指标、波动率模型、模式识别)
体积较大(WASM ~800KB)
支持 Node.js 和浏览器
适用场景: 需要完整功能、高级分析、模式识别
版本对比
特性 |
techkit |
techkit-full |
|---|---|---|
核心指标 |
✅ 158 |
✅ 158 |
高级分析 |
❌ |
✅ 31 |
风险指标 |
❌ |
✅ 是 |
波动率模型 |
❌ |
✅ 是 |
模式识别 |
❌ |
✅ 是 |
WASM 大小 |
~200KB |
~800KB |
推荐场景 |
大多数应用 |
完整功能需求 |
后端选择
TechKit Node.js 包会自动选择最优后端:
Native 后端(更快):
在支持的平台上自动使用
需要平台特定的二进制包(自动安装)
性能最佳
WASM 后端(通用):
在所有平台上可用
作为 Native 的自动回退
性能良好,体积稍大
验证安装
import { init, SMA, getBackend } from 'techkit';
// 初始化(必须在使用前调用)
await init();
// 检查使用的后端
console.log('当前后端:', getBackend()); // 'native' 或 'wasm'
// 测试基本功能
const sma = new SMA(20);
const result = sma.update(100.5);
if (result.valid) {
console.log('安装成功!SMA 值:', result.value);
}
// 清理资源
sma.dispose();
系统要求
Node.js: 16.0 或更高版本
支持的平台:
Linux (x86_64)
macOS (x86_64, arm64)
Windows (AMD64)
浏览器 / CDN 安装
TechKit 可以直接在浏览器中使用,无需构建工具:
使用 CDN (推荐)
<!DOCTYPE html>
<html>
<head>
<title>TechKit Browser Demo</title>
</head>
<body>
<script type="module">
// 从 CDN 导入
import { init, SMA, RSI } from 'https://cdn.jsdelivr.net/npm/techkit@1.2.7/+esm';
// 初始化
await init();
// 使用
const sma = new SMA(20);
const result = sma.update(100.5);
if (result.valid) {
console.log('SMA:', result.value);
}
sma.dispose();
</script>
</body>
</html>
使用 npm 包(配合构建工具)
如果您使用 Webpack、Vite、Rollup 等构建工具:
npm install techkit
然后在代码中:
import { init, SMA, RSI } from 'techkit';
await init();
// ... 使用代码
浏览器兼容性
Chrome/Edge: 支持
Firefox: 支持
Safari: 支持(需要较新版本)
移动浏览器: 支持
C++ 安装
作为 Git 子模块(推荐)
如果您在项目中使用 Git:
# 在您的项目中添加 TechKit 作为子模块
git submodule add https://github.com/yiivon/techkit.git libs/techkit
然后在 CMakeLists.txt 中:
# 添加 TechKit 子目录
add_subdirectory(libs/techkit)
# 链接到您的目标
target_link_libraries(your_app PRIVATE techkit::static)
# 或使用共享库
target_link_libraries(your_app PRIVATE techkit::shared)
使用 find_package
如果 TechKit 已安装在系统中:
find_package(TechKit REQUIRED)
target_link_libraries(your_app PRIVATE TechKit::techkit)
从源码构建
# 克隆仓库
git clone https://github.com/yiivon/techkit.git
cd techkit
# 创建构建目录
mkdir build && cd build
# 配置 CMake
cmake .. -DCMAKE_BUILD_TYPE=Release
# 编译
cmake --build .
# 安装(可选)
cmake --install . --prefix /usr/local
构建选项
选项 |
默认值 |
说明 |
|---|---|---|
|
ON |
构建共享库 (.so/.dll/.dylib) |
|
ON |
构建静态库 (.a/.lib) |
|
ON |
构建单元测试 |
|
OFF |
构建 Python 绑定 |
|
OFF |
构建 WebAssembly |
示例:自定义构建
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DTECHKIT_BUILD_SHARED=ON \
-DTECHKIT_BUILD_STATIC=OFF \
-DTECHKIT_BUILD_TESTS=OFF
安装验证清单
安装完成后,建议验证以下内容:
能够成功导入库
能够创建指标实例
能够计算基本指标(如 SMA)
结果符合预期
如果遇到问题,请查看 GitHub Issues 或提交新问题。