Install & Compatibility
Where this runs
tested against v0.5.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
py 3.10
✕ build_error
✓ 86.3s
py 3.11
✕ build_error
✓ 88.2s
py 3.12
✕ build_error
✓ 80.7s
py 3.13
✕ build_error
✓ 76.9s
py 3.9
✕ build_error
✕ timeout
5274MB installed
● package 5274MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Policy
✓ from tianshu.policy import Policy
✗ from tianshou.policy import Policy
Train a DQN agent on CartPole-v1 using off-policy training.
import gymnasium as gym
from tianshou.data import Collector, VectorReplayBuffer
from tianshou.env import DummyVectorEnv
from tianshou.policy import DQNPolicy
from tianshou.trainer import offpolicy_trainer
import torch
env = gym.make('CartPole-v1')
train_envs = DummyVectorEnv([lambda: gym.make('CartPole-v1') for _ in range(10)])
test_envs = DummyVectorEnv([lambda: gym.make('CartPole-v1') for _ in range(10)])
state_shape = env.observation_space.shape or env.observation_space.n
action_shape = env.action_space.shape or env.action_space.n
policy = DQNPolicy(
state_shape=state_shape,
action_shape=action_shape,
model=torch.nn.Linear(state_shape, action_shape),
optim=torch.optim.Adam(policy_network.parameters(), lr=1e-3),
).to('cpu')
buffer = VectorReplayBuffer(total_size=20000, buffer_num=len(train_envs))
collector = Collector(policy, train_envs, buffer)
test_collector = Collector(policy, test_envs)
def stop_fn(reward):
return reward >= 195
result = offpolicy_trainer(
policy=policy,
train_collector=collector,
test_collector=test_collector,
max_epoch=10,
step_per_epoch=1000,
step_per_collect=10,
episode_per_test=5,
batch_size=64,
stop_fn=stop_fn,
update_per_step=1,
)
print(f'Finished training in {result.timing.total_time_seconds}s')
Upgrade
Version history
2.0.1latest on PyPI · released Apr 2, 2026
Audit
Dependencies
gymnasiumrequiredEnvironment interface
torchrequiredNeural network backend
numpyrequiredNumerical operations
tensorboardoptionalLogging and visualization