安装LibreTranslate可以用docker,也可以用pip,在云环境无法使用docker,采用pip安装方式。
1、安装Python
避免错误安装3.10.11版本。https://www.python.org/ftp/python/3.10.11/python-3.10.11-amd64.exe
安装完成后,py --version 显示版本正常。
2、安装 / 修复最新 VC++ 2015–2022 x64 运行库
https://aka.ms/vs/17/release/vc_redist.x64.exe
3、安装libretranslate
#创建目录
cd /d D:\Web\LT
#创建虚拟空间
python -m venv venv
#激活 Python 虚拟环境(venv)
venv\Scripts\activate
#安装libretranslate
防止pip版本过低:python.exe -m pip install --upgrade pip
pip install libretranslate -i https://pypi.tuna.tsinghua.edu.cn/simple
#先刷新索引并查看可用包名
argospm update
argospm search
#安装双向语言对
argospm install translate-zh_en
argospm install translate-en_zh
argospm install translate-en_ru
argospm install translate-en_ar
argospm install translate-en_fr
argospm install translate-en_pt
argospm install translate-en_es
#查看已安装模型
argospm list
这个目录是已安装的语种 C:\Users\Administrator\.local\share\argos-translate\packages
#测试
libretranslate --load-only en,zh --port 5000
然后浏览器开 http://127.0.0.1:5000 验证翻译即可。
4、安装服务开机启动
#下载nssm
https://nssm.cc/download
#安装服务
nssm install LibreTranslate
Path:D:\web\LT\venv\Scripts\libretranslate.exe
Startup directory: D:\web\LT\venv\Scripts
Arguments: --load-only en,zh,ru,pt,fr,es,ar --threads 4 --translation-cache all
CPU 8 核设--threads 6~8,4 核设--threads 4就够。
设置名称为LibreTranslate翻译服务
用windows的账号和密码
需要在该目录新建3个文件
Input: D:\web\LT\stdin.log
Output: D:\web\LT\stdout.log
Error: D:\web\LT\stderr.log
#启动服务
nssm start LibreTranslate
#启动服务自动启动
sc config LibreTranslate start= auto
#如果不启动,修改服务
nssm edit LibreTranslate
#删除旧服务
nssm remove LibreTranslate confirm
5、基于IIS的启动
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="LTProxy" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://127.0.0.1:5000/{R:1}" />
</rule>
</rules>
</rewrite>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET,POST,OPTIONS" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
</customHeaders>
</httpProtocol>
<staticContent>
<mimeMap fileExtension=".woff" mimeType="font/woff" />
<mimeMap fileExtension=".woff2" mimeType="font/woff2" />
</staticContent>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="52428800" />
</requestFiltering>
</security>
</system.webServer>
</configuration>