Search code examples
pythonbinance

Binance API error. ImportError: No module named binance.client


I have imported the Binance package. I don't understand why it is not working. Can someone please point out what is wrong? This is my first time using an API and importing the necessary files.

from binance.client import Client
from binance.enums import *
import apiKey

client = Client(apiKey.apiKey ,apiKey.apiSecurity)

Error message:

Traceback (most recent call last):
  File "BinanceTrader.py", line 1, in <module>
    from binance.client import Client
ImportError: No module named binance.client

Solution

  • Are you sure that you've installed package python-binance ?

    If not try this pip install python-binance

    For more securable and comfortable method is virtual environment. You should look at https://docs.python.org/3/tutorial/venv.html


    Setting Up Virtual Environment

    1. open the command-line
    2. cd <path-your-project-root-folder>
    3. python -m venv env
    4. source env/bin/activate (Linux or MacOS) or .\env\Scripts\activate (Windows)
    5. install dependencies (in your case) pip install python-binance
    6. save the dependencies pip freeze > requirements.txt
    7. run your code! 🎉