bybit-exchange / pybit

Official Python3 API connector for Bybit's HTTP and WebSockets APIs.
Other
384 stars 129 forks source link

ImportError: cannot import name 'WebSocket' from partially initialized module 'pybit.unified_trading' (most likely due to a circular import) #199

Closed hugogva closed 5 months ago

hugogva commented 6 months ago

Hi guys,

I have just installed pybit latest version (5.6.2) using python (3.10.11) and try to run the following code (from ByBit docs):

from pybit.unified_trading import WebSocket
from time import sleep
ws = WebSocket(
    testnet=True,
    channel_type="spot",
)
def handle_message(message):
    print(message)
ws.ticker_stream(
    symbol="BTCUSDT",
    callback=handle_message
)
while True:
    sleep(1)

Here is the error I am getting:

Traceback (most recent call last): File "d:\MEGAsync\Coding\Blockchain\Crypto\ByBit Token Launch\RestAPI\websocket.py", line 1, in from pybit.unified_trading import WebSocket File "C:\Users\jedig\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pybit\unified_trading.py", line 18, in
from ._websocket_stream import _V5WebSocketManager File "C:\Users\jedig\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pybit_websocket_stream.py", line 1, in
import websocket File "d:\MEGAsync\Coding\Blockchain\Crypto\ByBit Token Launch\RestAPI\websocket.py", line 1, in from pybit.unified_trading import WebSocket ImportError: cannot import name 'WebSocket' from partially initialized module 'pybit.unified_trading' (most likely due to a circular import) (C:\Users\jedig\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pybit\unified_trading.py)

Kamsby commented 5 months ago

You cannot save your script name as websocket.py

Please save with other name and try it