ModuleNotFoundError:没有名为“binance.client”的模块;“binance”不是一个包

Gro*_*ony 2 python binance modulenotfounderror

嘿,我是 Stack Over Flow 和 Python 的新手,但想学习并希望有人可以帮助我。我正在尝试在 python 中开发一个币安交易机器人。请参阅下面我的脚本:


from binance.client import Client

class Trader:
    def __init__(self, file):
        self.connect(file)

    """ Creates Binance client """
    def connect(self,file):
        lines = [line.rstrip('\n') for line in open(file)]
        key = lines[0]
        secret = lines[1]
        self.client = Client(key, secret)

    """ Gets all account balances """
    def getBalances(self):
        prices = self.client.get_withdraw_history()
        return prices

filename = 'API credentials.txt'
trader = Trader(filename)
balances = trader.getBalances()
print(balances)
Run Code Online (Sandbox Code Playgroud)

该脚本给我一个模块未找到错误,请参阅下面的完整详细信息:

PyDev console: starting.
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 bit (Intel)] on win32
runfile('C:/Users/ryanf/PycharmProjects/trading bot/trader.py', wdir='C:/Users/ryanf/PycharmProjects/trading bot')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Program Files\JetBrains\PyCharm Edu 2020.1.1\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm Edu 2020.1.1\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/ryanf/PycharmProjects/trading bot/trader.py", line 1, in <module>
    from binance.client import Client
  File "C:\Program Files\JetBrains\PyCharm Edu 2020.1.1\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'binance.client'; 'binance' is not a package
Run Code Online (Sandbox Code Playgroud)

希望有人能在这里提供一些建议,将不胜感激。

KER*_*ERR 6

确保同一文件夹中没有任何名为“binance”的文件 - 这就是我遇到的情况。