0

From Jupyter Notebook I ran pip install binance. Running from binance.client import Client gives the error above. I have renamed the binance.py file as mentioned in similar questions however I'm still getting the error. I haven't installed for one version of python while trying to run my code with another as mentioned in another question. Trying pip uninstall gives "WARNING: Skipping binance as it is not installed.".

How can I get the python-binance package to work?

Edit: Following Wayne's comment I tried %conda install -c conda-forge python-binance and encounter a new error when trying to import: No module named 'importlib.readers'

Edit 2: conda list and pip list both run without errors.

My traceback:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[2], line 1
----> 1 from binance.client import Client

File ~\anaconda3\envs\py3\lib\site-packages\binance\__init__.py:9
      1 """An unofficial Python wrapper for the Binance exchange API v3
      2 
      3 .. moduleauthor:: Sam McHardy
      4 
      5 """
      7 __version__ = '1.0.16'
----> 9 from binance.client import Client, AsyncClient  # noqa
     10 from binance.depthcache import DepthCacheManager, OptionsDepthCacheManager, ThreadedDepthCacheManager  # noqa
     11 from binance.streams import BinanceSocketManager, ThreadedWebsocketManager  # noqa

File ~\anaconda3\envs\py3\lib\site-packages\binance\client.py:7
      5 import hashlib
      6 import hmac
----> 7 import requests
      8 import time
      9 from operator import itemgetter

File ~\anaconda3\envs\py3\lib\site-packages\requests\__init__.py:147
    144 import logging
    145 from logging import NullHandler
--> 147 from . import packages, utils
    148 from .__version__ import (
    149     __author__,
    150     __author_email__,
   (...)
    158     __version__,
    159 )
    160 from .api import delete, get, head, options, patch, post, put, request

File ~\anaconda3\envs\py3\lib\site-packages\requests\utils.py:58
     54 from .structures import CaseInsensitiveDict
     56 NETRC_FILES = (".netrc", "_netrc")
---> 58 DEFAULT_CA_BUNDLE_PATH = certs.where()
     60 DEFAULT_PORTS = {"http": 80, "https": 443}
     62 # Ensure that ', ' is used to preserve previous delimiter behavior.

File ~\anaconda3\envs\py3\lib\site-packages\certifi\core.py:71, in where()
     58 global _CACERT_PATH
     59 if _CACERT_PATH is None:
     60     # This is slightly janky, the importlib.resources API wants you
     61     # to manage the cleanup of this file, so it doesn't actually
   (...)
     69     # it will do the cleanup whenever it gets garbage collected, so
     70     # we will also store that at the global level as well.
---> 71     _CACERT_CTX = get_path("certifi", "cacert.pem")
     72     _CACERT_PATH = str(_CACERT_CTX.__enter__())
     74 return _CACERT_PATH

File ~\anaconda3\envs\py3\lib\importlib\resources.py:119, in path(package, resource)
    112         else:
    113             return BytesIO(data)
    116 def open_text(package: Package,
    117               resource: Resource,
    118               encoding: str = 'utf-8',
--> 119               errors: str = 'strict') -> TextIO:
    120     """Return a file-like object opened for text reading of the resource."""
    121     resource = _normalize_path(resource)

File ~\anaconda3\envs\py3\lib\importlib\_common.py:52, in get_resource_reader(package)

ModuleNotFoundError: No module named 'importlib.readers'
Eli Bain
  • 23
  • 3
  • Did you try first try installing Twisted and then run `%pip install python-binance` inside a cell in your notebook and then restart the kernel? (Based on [here](https://stackoverflow.com/a/66105458/8508004) and [here](https://pypi.org/project/python-binance/).) Which similar questions suggest renaming? Please point to specifics when saying things like that. If that doesn't work, provide more details because if you ran the install correctly in the first place and it didn't have errors when you tried, you shouldn't see this. – Wayne Feb 06 '23 at 00:58
  • If you are just getting started, you may want to consider switching to using Anaconda distribution and using `%conda install -c conda-forge python-binance` (based on [here](https://anaconda.org/conda-forge/python-binance) inside your notebook to install it as it seems to be a complex package that pip alone cannot handle well. Anaconda/conda/mamba has more complex recipes associated and can often handle more complex installs than pip can. If you do switch, you always try to see if conda can install it and use that solution primarily. Only fall back to using pip for packages conda doesn't have. – Wayne Feb 06 '23 at 01:02
  • Hi @Wayne please see the result of switching to Anaconda above – Eli Bain Feb 06 '23 at 02:23
  • You still aren't including the traceback which would help people tell what is going on and suggest things. Did you already have Anaconda installed or is this a new installation today? Because without seeing the actual traceback, it strikes me as a mismatch where you don't have a consistent matching set of necessary things installed. This sort of thing can happen when you start mixing and matching using pip when you should primarily have been using Anaconda/conda because that was your main package manager. – Wayne Feb 06 '23 at 05:03
  • Can you run `%conda list` and does it work and not give the `importlib.readers` error? What about if you run `%pip list`? One of the few posts matching your error is [here](https://www.reddit.com/r/ManjaroLinux/comments/s783e2/help_needed_with_pip/). They reported seeing it when running `%pip list`. Note the suggestion is trying to see if something is referencing a different version. My concern is that since you seemed to be not sticking to using `conda` to install whenever you could that you've got that. If you don't have a lot of environments you need mad in Anaconda, maybe ... – Wayne Feb 06 '23 at 05:36
  • a full uninstall and reinstall is in order. **But you probably want to wait and just keep that idea in mind if no one else comes up with anything first after you share more information.** Full uninstall directions are [here](https://docs.anaconda.com/anaconda/install/uninstall/). [This person](https://stackoverflow.com/a/72844567/8508004) was getting different importlib errors and that supposedly fixed it. So it wasn't even the same error. That's another reason I'm suggesting to keep it in mind as an option but wait maybe until more people have time to see your information. – Wayne Feb 06 '23 at 05:42
  • The comment two above should be ending , "... If you don't have a lot of environments you need made* in Anaconda...". – Wayne Feb 06 '23 at 05:44

1 Answers1

0

As suggested in the question comments, my problem was inconsistency of installed packages due to using pip instead of conda. Uninstalling and reinstalling Anaconda fixed the module not found error.

Eli Bain
  • 23
  • 3