Python 环境问题

Python 环境问题

Posted by laohuang on Sunday, March 9, 2025

安装 Python 依赖网速慢问题

在海外机器
mkdir /pot/mod/
pip download -d /opt/mod  -r requirements.txt
tar zcvf /tmp/mod.tgz /opt/mod/*

Copy 到国内机器
tar zxvf /tmp/mod.tgz -C /opt/mod/
python3 -m venv ./venv/
cd venv/bin
source ./activate

pip install --no-index --find-links=/opt/mod/ -r requirements.txt

里面会有 tar.gz 文件会报如下错

Processing /opt/ai-hub/mod/peewee-3.17.9.tar.gz
  Installing build dependencies ... error
  error: subprocess-exited-with-error

  × pip subprocess to install build dependencies did not run successfully.
  │ exit code: 1
  ╰─> [4 lines of output]
      Looking in links: /opt/ai-hub/mod/
      Processing /opt/ai-hub/mod/setuptools-75.8.2-py3-none-any.whl
      ERROR: Could not find a version that satisfies the requirement wheel (from versions: none)
      ERROR: No matching distribution found for wheel
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> See above for output.

这时候需要单独 install

pip install /opt/mod/peewee-3.17.9.tar.gz

然后继续安装

pip install --no-index --find-links=/opt/mod/ -r requirements.txt

服务启动脚本示例

root@ai-hub:~# cat /etc/systemd/system/aihub.service
[Unit]
Description=Ai-Hub Service
After=network.target

[Service]
ExecStartPre=/bin/bash -c 'source /opt/ai-hub/venv/bin/activate'
Environment=ENV=prod
WorkingDirectory=/opt/ai-hub/main
ExecStart=/opt/ai-hub/venv/bin/python3  /opt/ai-hub/main/server.py

Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target

「真诚赞赏,手留余香」

LaoHuang Blog

真诚赞赏,手留余香

使用微信扫描二维码完成支付