1、安裝虛擬環(huán)境 注意,一定要python的版本 一定要 3.9及以下?。?br>否則一直會(huì)出錯(cuò) ImportError: cannot import name 'COMMON_SAFE_ASCII_CHARACTERS’ from 'charset_normalizer.constant’ (D:\anaconda3\envs\AIGC\lib\site-packages\charset_normalizer\constant.py) pip install chardet pip install charset-normalizer==2.1.0 都不管用 要確保python的版本號(hào) conda install python==3.8 2、安裝openai ERROR: Could not find a version that satisfies the requirement openai (from versions: none) ERROR: No matching distribution found for openai 這時(shí)候用國(guó)內(nèi)源就好了 pip install openai -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com 3、連接不上 openai.error.APIConnectionError: Error communicating with OpenAI: HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /v1/chat/completions (Caused by ProxyError('Cannot connect to proxy.', OSError(0, 'Error'))) 后來(lái)在知乎回答—— 找到了答案 urllib3的版本問(wèn)題,環(huán)境內(nèi)的urllib3版本是1.26.14版本,回退到1.25.11版本問(wèn)題就解決了。 檢查了一下urllib3的更新日志,應(yīng)該是1.26.0的修改導(dǎo)致的: 最后 conda install urllib3==1.25.11 4、一直顯示無(wú)chatCompletion AttributeError: module 'openai' has no attribute 'ChatCompletion' openai的版本號(hào)不夠新,參照2進(jìn)行更新 pip install -U openai -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com 能跑通啦,棒棒?。。。?/p> 5、no model named win32api pip install win32api ERROR: Could not find a version that satisfies the requirement win32api (from versions: none) ERROR: No matching distribution found for win32api 實(shí)際的安裝方法 conda install win32api 6、連接錯(cuò)誤 解決方法 ①打開文件路徑:D:\Anaconda3\envs\py\Lib\site-packages\openai\api_reuqestor.py(openai庫(kù)路徑) ②找到if not hasattr(_thread_context,“session”): 方法,并在此方法上加入代理。(此方法大概在512行) # proxy = { # 'http': 'http://<代理ip>:<代理端口>', # 'https': 'https://<代理ip>:<代理端口>' # } proxy={ 'http':'127.0.0.1:10809', 'https':'127.0.0.1:10809' } ③在result = _thread_context.session.request(中加入代理 result = _thread_context.session.request( method, abs_url, headers=headers, data=data, files=files, stream=stream, timeout=request_timeout if request_timeout else TIMEOUT_SECS, proxies=proxy # 新增此行 ) result = _thread_context.session.request( method, abs_url, headers=headers, data=data, files=files, stream=stream, timeout=request_timeout if request_timeout else TIMEOUT_SECS, proxies=proxy # 新增此行 ) 再次運(yùn)行API測(cè)試代碼發(fā)現(xiàn)已經(jīng)成功返回?cái)?shù)據(jù) 版權(quán)聲明:本文為博主原創(chuàng)文章,遵循 CC 4.0 BY-SA 版權(quán)協(xié)議,轉(zhuǎn)載請(qǐng)附上原文出處鏈接和本聲明vb.net教程C#教程python教程。 原文鏈接:https://blog.csdn.net/weixin_43818488/article/details/129811845 |
|
來(lái)自: 昵稱21609410 > 《python》