1.把项目拉下来,然后进入文件夹,然后使用pip安装库
git clone https://github.com/yihong0618/bilingual_book_maker.git
pip install -r requirements.txt
然后报错.
$ pip install -r requirements.txt
WARNING: Ignoring invalid distribution -ip (d:\python3.8.7rc1\lib\site-packages)
WARNING: Ignoring invalid distribution -ip (d:\python3.8.7rc1\lib\site-packages)
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status =None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in vio lation of protocol (_ssl.c:1125)'))': /simple/bs4/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status =None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in vio lation of protocol (_ssl.c:1125)'))': /simple/bs4/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status =None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in vio lation of protocol (_ssl.c:1125)'))': /simple/bs4/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status =None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in vio lation of protocol (_ssl.c:1125)'))': /simple/bs4/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status =None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in vio lation of protocol (_ssl.c:1125)'))': /simple/bs4/
Could not fetch URL https://pypi.org/simple/bs4/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retrie s exceeded with url: /simple/bs4/ (Caused by SSLError(SSLEOFError(8, 'EOF occurr ed in violation of protocol (_ssl.c:1125)'))) - skipping
ERROR: Could not find a version that satisfies the requirement bs4 (from version s: none)
ERROR: No matching distribution found for bs4
WARNING: Ignoring invalid distribution -ip (d:\python3.8.7rc1\lib\site-packages)
WARNING: Ignoring invalid distribution -ip (d:\python3.8.7rc1\lib\site-packages)
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retrie s exceeded with url: /simple/pip/ (Caused by SSLError(SSLEOFError(8, 'EOF occurr ed in violation of protocol (_ssl.c:1125)'))) - skipping
使用国内源的话,可以正常安装.
pip install bs4 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
但是每个都要手动安装,可以考虑配置代理,单次设置命令如下:
pip install -r requirements.txt --proxy=127.0.0.1:7890
2.配置好这些库之后,来测试一下.
# 如果你想快速测一下
python3 make_book.py --book_name test_books/animal_farm.epub --openai_key ${openai_key} --test
# 或翻译完整本书
python3 make_book.py --book_name test_books/animal_farm.epub --openai_key ${openai_key} --language zh-hans
我这里运行如下命令
python make_book.py --book_name test_books/animal_farm.epub --openai_key sk-Fbxx --test
报错:
module 'openai' has no attribute 'ChatCompletion' will sleep 60 seconds
module 'openai' has no attribute 'ChatCompletion'
需更新openai,使用
pip install openai --upgrade
使用 pip list
查看版本, 但是openai 版本仍然是0.26.5
从官网上可以看到,目前官网上最新的是0.27.2
https://pypi.org/project/openai/
直接安装时找不到这个版本,因此无法升级.
$ pip install openai==0.27.2
WARNING: Ignoring invalid distribution -ip (d:\python3.8.7rc1\lib\site-packages)
WARNING: Ignoring invalid distribution -ip (d:\python3.8.7rc1\lib\site-packages)
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)'))': /simple/openai/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)'))': /simple/openai/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)'))': /simple/openai/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)'))': /simple/openai/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)'))': /simple/openai/
Could not fetch URL https://pypi.org/simple/openai/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/openai/ (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)'))) - skipping
ERROR: Could not find a version that satisfies the requirement openai==0.27.2 (from versions: none)
ERROR: No matching distribution found for openai==0.27.2
WARNING: Ignoring invalid distribution -ip (d:\python3.8.7rc1\lib\site-packages)
WARNING: Ignoring invalid distribution -ip (d:\python3.8.7rc1\lib\site-packages)
WARNING: Ignoring invalid distribution -ip (d:\python3.8.7rc1\lib\site-packages)
升级时,配置代理.
pip install openai --upgrade --proxy=127.0.0.1:7890
再执行python命令测试翻译功能.报错
D:\Python3.8.7rc1\lib\site-packages\ebooklib\epub.py:1395: UserWarning: In the future version we will turn defa ult option ignore_ncx to True.
warnings.warn('In the future version we will turn default option ignore_ncx to True.')
0%| | 0/10 [00:00<?, ?it/s]
Animal Farm: A Fairy Story
Error communicating with OpenAI: HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded wit h url: /v1/chat/completions (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1 125)'))) will sleep 60 seconds
Error communicating with OpenAI: HTTPSConnectionPool(host='api.openai.com',
port=443): Max retries exceeded with url: /v1/chat/completions (Caused by
SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol
(_ssl.c:1125)')))
you can resume it next time
0%| | 0/10 [01:00<?, ?it/s]
这里需配置proxy,开全局,这里注意改成自己的openai_key .
python make_book.py --book_name test_books/animal_farm.epub --openai_key sk-Fbxx --test --proxy=127.0.0.1:7890
然后会生成animal_farm_bilingual.epub,这个就是生成的中英文对照版本的电子档书籍,不过这个命令只会翻译一点点.
image.png
image.png
测试一点点的话,只花了0.01的额度,不过免费的额度用得还是很快的.
参考链接:
https://github.com/yihong0618/bilingual_book_maker
报错了,AttributeError: module 'openai' has no attribute 'ChatCompletion'
网友评论