-1
import python-binance

That's it. Yup. When I try importing this library all I get is

  File "main.py", line 1
    import python-binance
                 ^
SyntaxError: invalid syntax

Either I don't know what I'm doing or something is horribly wrong.

lucas
  • 23
  • 4
  • 3
    Does just `import binance` do what you expect? – Wander Nauta Jul 17 '21 at 19:03
  • 3
    Probably the module is not called `python-binance` to begin with. What did the documentation of the module you were trying to import have to say about this? – mkrieger1 Jul 17 '21 at 19:03
  • python module names can't contain dashes. if you want to import a file with dashes in its name, then use `importlib.import_module`. – Abdou Jul 17 '21 at 19:06

1 Answers1

2

You can't. Take a look at this solution. You would need to rename the module with an underscore.

In your case, the python-binance library doesn't need to be imported like that. All you need to do is import the client like this:

from binance.client import Client
client = Client(api_key, api_secret)
DogEatDog
  • 2,899
  • 2
  • 36
  • 65
  • 1
    ah. looked closer at docs: yup. it's binance.client. thank you for pointing out my foolishness! <3 – lucas Jul 17 '21 at 19:07
  • You're welcome. Please accept this answer if it worked for you. Some Python Packages are like that in not having different module names than what the package is called. Also, some module names are shortened or changed as a informal custom. For example, the `pandas` library is often shorted to `pd`... e.g. `import pandas as pd` – DogEatDog Jul 17 '21 at 19:10