嘿,我对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)这个脚本给了我一个模块未找到的错误,请参阅下面的详细信息:
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希望有人能在这里提供一些建议,这将是非常感谢。
发布于 2021-05-09 07:17:04
确保在同一个文件夹中没有任何名为"binance“的文件--这就是我遇到的情况。
发布于 2020-05-22 21:22:33
将推荐docs:https://docs.python.org/3/reference/import.html --这些是非常长的文档,但是这里有“亮点”:
import sys; print(sys.path),还可以在运行脚本的位置检查PYTHONPATH环境变量。如果您知道包或模块的位置,请确保在上面的语句中列出了该位置。pip install python-binance,如果从命令行运行pip list,是否列出了“二进制”?binance是当前目录中的子目录,则可能缺少一个__init__.py文件--参见包裹上的文档。PYTHONPATH或进行其他更改时,请注意不明确;避免创建一个模块可能来自的多个源,并以避免隐藏现有模块的方式命名您的模块/包。请参阅关于搜索路径优先级的文档发布于 2021-06-05 18:55:10
通过调用您的文件binance.py,然后尝试从binance.client导入,python正在查找您的binance.py文件。
如果您重命名本地文件,那么您就不会有问题。
https://stackoverflow.com/questions/61963875
复制相似问题