python-binance icon indicating copy to clipboard operation
python-binance copied to clipboard

Cannot import binance.client on Ubuntu 18.04

Open nshiff opened this issue 7 years ago • 3 comments

Expected: proceed through import statement Observed: runtime error describing missing regex module. The error happens consistently across python3 as well as the legacy python2.

python3

$ date
Tue Feb 19 16:01:49 EST 2019

$ pip3 install python-binance --no-cache-dir
Collecting python-binance
  Downloading https://files.pythonhosted.org/packages/82/e1/f1b2346fdb0fcfc397376798425578f64198d7d7a5a079c8864ae0cbcdc0/python-binance-0.7.1.tar.gz
Collecting requests (from python-binance)
  Downloading https://files.pythonhosted.org/packages/7d/e3/20f3d364d6c8e5d2353c72a67778eb189176f08e873c9900e10c0287b84b/requests-2.21.0-py2.py3-none-any.whl (57kB)
<snip>
Successfully installed Automat-0.7.0 PyHamcrest-1.9.0 Twisted-18.9.0 asn1crypto-0.24.0 attrs-18.2.0 autobahn-19.2.1 certifi-2018.11.29 cffi-1.12.1 chardet-3.0.4 constantly-15.1.0 cryptography-2.5 dateparser-0.7.1 hyperlink-18.0.0 idna-2.8 incremental-17.5.0 pyOpenSSL-19.0.0 pyasn1-0.4.5 pyasn1-modules-0.2.4 pycparser-2.19 python-binance-0.7.1 python-dateutil-2.8.0 pytz-2018.9 regex-2019.2.19 requests-2.21.0 service-identity-18.1.0 setuptools-40.8.0 six-1.12.0 txaio-18.8.1 tzlocal-1.5.1 urllib3-1.24.1 zope.interface-4.6.0
Segmentation fault (core dumped)

$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from binance.client import Client
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/nate/.local/lib/python3.6/site-packages/binance/client.py", line 8, in <module>
    from .helpers import date_to_milliseconds, interval_to_milliseconds
  File "/home/nate/.local/lib/python3.6/site-packages/binance/helpers.py", line 3, in <module>
    import dateparser
  File "/home/nate/.local/lib/python3.6/site-packages/dateparser/__init__.py", line 4, in <module>
    from .date import DateDataParser
  File "/home/nate/.local/lib/python3.6/site-packages/dateparser/date.py", line 10, in <module>
    import regex as re
  File "/home/nate/.local/lib/python3.6/site-packages/regex.py", line 400, in <module>
    import regex._regex_core as _regex_core
ModuleNotFoundError: No module named 'regex._regex_core'; 'regex' is not a package

python2

$ pip install python-binance
Collecting python-binance
<snip>
Successfully installed Automat-0.7.0 PyHamcrest-1.9.0 Twisted-18.9.0 asn1crypto-0.24.0 attrs-18.2.0 autobahn-19.2.1 certifi-2018.11.29 cffi-1.12.1 chardet-3.0.4 constantly-15.1.0 cryptography-2.5 dateparser-0.7.1 enum34-1.1.6 hyperlink-18.0.0 idna-2.8 incremental-17.5.0 ipaddress-1.0.22 pyOpenSSL-19.0.0 pyasn1-0.4.5 pyasn1-modules-0.2.4 pycparser-2.19 python-binance-0.7.1 python-dateutil-2.8.0 pytz-2018.9 regex-2019.2.19 requests-2.21.0 service-identity-18.1.0 setuptools-40.8.0 six-1.12.0 txaio-18.8.1 tzlocal-1.5.1 urllib3-1.24.1 zope.interface-4.6.0
Segmentation fault (core dumped)

$ python
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from binance.client import Client
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/nate/.local/lib/python2.7/site-packages/binance/client.py", line 8, in <module>
    from .helpers import date_to_milliseconds, interval_to_milliseconds
  File "/home/nate/.local/lib/python2.7/site-packages/binance/helpers.py", line 3, in <module>
    import dateparser
  File "/home/nate/.local/lib/python2.7/site-packages/dateparser/__init__.py", line 4, in <module>
    from .date import DateDataParser
  File "/home/nate/.local/lib/python2.7/site-packages/dateparser/date.py", line 13, in <module>
    from dateparser.date_parser import date_parser
  File "/home/nate/.local/lib/python2.7/site-packages/dateparser/date_parser.py", line 8, in <module>
    from .timezone_parser import pop_tz_offset_from_string
  File "/home/nate/.local/lib/python2.7/site-packages/dateparser/timezone_parser.py", line 79, in <module>
    _tz_offsets = list(get_tz_offsets())
  File "/home/nate/.local/lib/python2.7/site-packages/dateparser/timezone_parser.py", line 70, in get_tz_offsets
    yield get_offset(tz_obj, regex, repl=replace, replw=replacewith)
  File "/home/nate/.local/lib/python2.7/site-packages/dateparser/timezone_parser.py", line 57, in get_offset
    'regex': re.compile(re.sub(repl, replw, regex % tz_obj[0]), re.IGNORECASE),
  File "/home/nate/.local/lib/python2.7/site-packages/regex.py", line 276, in sub
    endpos, concurrent)
ImportError: No module named regex

nshiff avatar Feb 19 '19 21:02 nshiff

Following the stack trace I found a slightly surprising result. If I simply run import dateparser the problem is reproduced. Further, the same behavior occurs if I run import regex.

I am not certain what that indicates, but in my layman's understanding, it appears that the issue may not be with python-binance itself, and not even with its dependency dateparser directly, but instead something funky happening with import regex which occurs inside dateparser.

edit: indeed the modules appear to exist and to be installed...

(venv) $ pip3 install dateparser
Requirement already satisfied: dateparser in ./venv/lib/python3.6/site-packages (0.7.1)
Requirement already satisfied: regex in ./venv/lib/python3.6/site-packages (from dateparser) (2019.2.19)
Requirement already satisfied: pytz in ./venv/lib/python3.6/site-packages (from dateparser) (2018.9)
Requirement already satisfied: python-dateutil in ./venv/lib/python3.6/site-packages (from dateparser) (2.8.0)
Requirement already satisfied: tzlocal in ./venv/lib/python3.6/site-packages (from dateparser) (1.5.1)
Requirement already satisfied: six>=1.5 in ./venv/lib/python3.6/site-packages (from python-dateutil->dateparser) (1.12.0)
(venv) $ pip3 install regex
Requirement already satisfied: regex in ./venv/lib/python3.6/site-packages (2019.2.19)

nshiff avatar Feb 19 '19 21:02 nshiff

This appears to be a known issue, perhaps relating to the cffi package. https://github.com/sammchardy/python-binance/issues/59

nshiff avatar Feb 22 '19 03:02 nshiff

I have exactly the same problem, anyone please help!

savelifes91 avatar Sep 06 '22 13:09 savelifes91