[python오류] openai, googletrans 동시 사용 오류 발생 수정 cannot import name 'BaseTransport' from 'httpx'
python 컴파일 중 오류 발생
openai와 googletans를 활용 프로그램을 만들다 보니.. 오류가 발생했다. 이전에는 크게 문제가 없없는데.. 갑자기 또 오류가 발생하네..
ImportError: cannot import name 'BaseTransport' from 'httpx' (C:\Python\PyNW\Lib\site-packages\httpx\__init__.py)
컴파일 하면 위와 같은 메시지가 뜨면서 컴파일이 되지 않는다. 뭐가 문제 일까? 해결방법은 무엇일까?
1. Python openai, googletrans 충돌 발생
openai와 googletans는 모두 httpx를 사용하는데 최근에 openai가 업데이트를 하면서 httpx 최신버전을 사용하고 googletans는 구버전 httpx를 참조하여 발생한 오류이다.
Traceback (most recent call last):
File "C:\Python\PyNW\Lib\multiprocessing\process.py", line 314, in _bootstrap
self.run()
File "C:\Python\PyNW\Lib\multiprocessing\process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "C:\Python\PyNW\Lib\site-packages\uvicorn\_subprocess.py", line 78, in subprocess_started
target(sockets=sockets)
File "C:\Python\PyNW\Lib\site-packages\uvicorn\server.py", line 62, in run
return asyncio.run(self.serve(sockets=sockets))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python\PyNW\Lib\asyncio\runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "C:\Python\PyNW\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python\PyNW\Lib\asyncio\base_events.py", line 654, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "C:\Python\PyNW\Lib\site-packages\uvicorn\server.py", line 69, in serve
config.load()
File "C:\Python\PyNW\Lib\site-packages\uvicorn\config.py", line 458, in load
self.loaded_app = import_from_string(self.app)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python\PyNW\Lib\site-packages\uvicorn\importer.py", line 21, in import_from_string
module = importlib.import_module(module_str)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python\PyNW\Lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "C:\py-nongwoo\NW_FT_API_001\run.py", line 1, in <module>
from apps.main import app
File "C:\py-nongwoo\NW_FT_API_001\apps\main.py", line 20, in <module>
from apps.routers_extn import api_aligo_kakao, api_aligo_sms, api_hanjin, api_ilyang, api_test_t
File "C:\py-nongwoo\NW_FT_API_001\apps\routers_extn\api_test_t.py", line 10, in <module>
from openai import OpenAI
File "C:\Python\PyNW\Lib\site-packages\openai\__init__.py", line 8, in <module>
from . import types
from .image import Image as Image
File "C:\Python\PyNW\Lib\site-packages\openai\types\image.py", line 5, in <module>
from .._models import BaseModel
File "C:\Python\PyNW\Lib\site-packages\openai\_models.py", line 22, in <module>
from ._types import (
File "C:\Python\PyNW\Lib\site-packages\openai\_types.py", line 23, in <module>
from httpx import URL, Proxy, Timeout, Response, BaseTransport, AsyncBaseTransport
ImportError: cannot import name 'BaseTransport' from 'httpx' (C:\Python\PyNW\Lib\site-packages\httpx\__init__.py)
2. 해결 방법
openai와 googletans 동시에 사용하면 발생하고 있는 일시적인 오류 같고 곧 googletans 쪽에서 패치가 나올껀데.. 일시적으로 처리해보자
방법1 : openai 버전 다운그레이드
pip install -U openai==0.28
방법2 : googletans 삭제 후 httpx 버전 업그레이드
pip uninstall googletrans
pip install -U httpx
마무리
오늘은 ImportError: cannot import name 'BaseTransport' from 'httpx' 문구 오류 발생 시 처리 방법에 대해서 알아보았습니다. 빨리 googletans 패치가 나왔으면 좋겠네요. 쉽고 빠른 코딩라이프를 위해 모두 화이팅!
댓글
댓글 쓰기