You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python 3.7运行PiSugar项目遇TypeError错误求助

Fixing the TypeError: 'type' object is not subscriptable in PiSugar Server with Python 3.7

Hey there, I’ve run into this exact kind of issue before with older Python versions—let’s break down what’s happening and how to fix it.

Why This Error Happens

The error points directly to this function definition:

def connect_tcp(host="127.0.0.1", port=8423, timeout: float = None) -> tuple[socket.socket, socket.socket]:

Python 3.7 doesn’t support the tuple[Type1, Type2] shorthand for type annotations. This syntax was introduced in Python 3.9 via PEP 585, so your 3.7 interpreter can’t parse it, hence the "type not subscriptable" error.

Step-by-Step Fixes

Option 1: Modify the Code to Be 3.7-Compatible (Quick Fix)

Find the file containing the connect_tcp function (it’s likely in the project’s core networking module), then make these small changes:

  • At the top of the file, add this import:
    import typing
    
  • Replace the return type annotation from tuple[socket.socket, socket.socket] to typing.Tuple[socket.socket, socket.socket]

Alternatively, you can add this line at the very top of the file (before any other imports) to enable delayed annotation parsing—this lets 3.7 understand the newer syntax without rewriting the annotation:

from __future__ import annotations

Pro tip: Backup the original file before making changes to avoid breaking anything if you make a typo.

Option 2: Upgrade Python to 3.9+ (Recommended Long-Term Fix)

Python 3.7 is end-of-life (no longer receiving security updates), so upgrading to a supported version is better for both compatibility and security. On Debian:

  1. Update your package list:
    sudo apt update
    
  2. Install Python 3.9 and virtual environment support:
    sudo apt install python3.9 python3.9-venv
    
  3. Create a virtual environment to isolate the PiSugar project from your system’s default Python:
    python3.9 -m venv pisugar-env
    source pisugar-env/bin/activate
    
  4. Install the project’s dependencies and run it as usual:
    pip install -r requirements.txt
    # Start the PiSugar server with your normal command
    

Option 3: Check for a Python 3.7-Compatible Project Version

If you can’t upgrade Python or modify code, quickly scan the project’s tags/branches to see if there’s an older release that explicitly supports 3.7. Since you mentioned developer response is slow, this might not be available, but it’s worth a quick check just in case.


内容的提问来源于stack exchange,提问作者Insanelysick

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 17:55:38