• Client API
  • Lightstreamer in Anaconda Python Distribution

Hello all,

I've been just starting to try to use the Lightstreamer client in Python 3.9 in the Spyder IDE, and I get an error on import.

The only line of code I run is:
from lightstreamer_client import *
and I get the following output:
Traceback (most recent call last):

  Cell In[1], line 1
    from lightstreamer_client import *


  File ~\anaconda3\envs\Economic\lib\site-packages\lightstreamer_client\__init__.py:1
    from .com_lightstreamer_client import *


  File ~\anaconda3\envs\Economic\lib\site-packages\lightstreamer_client\com_lightstreamer_client.py:16034
    com_lightstreamer_internal_EventDispatcher.executor = com_lightstreamer_internal_EventDispatcher.createExecutor()


  File ~\anaconda3\envs\Economic\lib\site-packages\lightstreamer_client\com_lightstreamer_client.py:2318 in createExecutor
    return hx_concurrent_executor_Executor.create(1)


  File ~\anaconda3\envs\Economic\lib\site-packages\lightstreamer_client\com_lightstreamer_client.py:1902 in create
    return hx_concurrent_executor_ThreadPoolExecutor(maxConcurrent,autostart)


  File ~\anaconda3\envs\Economic\lib\site-packages\lightstreamer_client\com_lightstreamer_client.py:1978 in __init__
    super().__init__()


  File ~\anaconda3\envs\Economic\lib\site-packages\lightstreamer_client\com_lightstreamer_client.py:1887 in __init__
    super().__init__()


  File ~\anaconda3\envs\Economic\lib\site-packages\lightstreamer_client\com_lightstreamer_client.py:1781 in __init__
    haxe_Log.trace((("[" + Std.string(self)) + "] instantiated."),_hx_AnonObject({'fileName': "hx/concurrent/Service.hx", 'lineNumber': 56, 'className': "hx.concurrent.ServiceBase", 'methodName': "new"}))


  File ~\anaconda3\envs\Economic\lib\site-packages\lightstreamer_client\com_lightstreamer_client.py:2316 in _hx_local_0
    python_Lib.printString((("" + Std.string(haxe_Log.formatOutput(v,infos))) + HxOverrides.stringOrNull(python_Lib.lineEnd)))


  File ~\anaconda3\envs\Economic\lib\site-packages\lightstreamer_client\com_lightstreamer_client.py:1687 in printString
    python_lib_Sys.stdout.buffer.write(_hx_str.encode("utf-8", "strict"))


AttributeError: 'TTYOutStream' object has no attribute 'buffer'




from lightstreamer import *


import lightstreamer_client
Traceback (most recent call last):


  Cell In[3], line 1
    import lightstreamer_client


  File ~\anaconda3\envs\Economic\lib\site-packages\lightstreamer_client\__init__.py:1
    from .com_lightstreamer_client import *


  File ~\anaconda3\envs\Economic\lib\site-packages\lightstreamer_client\com_lightstreamer_client.py:16034
    com_lightstreamer_internal_EventDispatcher.executor = com_lightstreamer_internal_EventDispatcher.createExecutor()


  File ~\anaconda3\envs\Economic\lib\site-packages\lightstreamer_client\com_lightstreamer_client.py:2318 in createExecutor
    return hx_concurrent_executor_Executor.create(1)


  File ~\anaconda3\envs\Economic\lib\site-packages\lightstreamer_client\com_lightstreamer_client.py:1902 in create
    return hx_concurrent_executor_ThreadPoolExecutor(maxConcurrent,autostart)


  File ~\anaconda3\envs\Economic\lib\site-packages\lightstreamer_client\com_lightstreamer_client.py:1978 in __init__
    super().__init__()


  File ~\anaconda3\envs\Economic\lib\site-packages\lightstreamer_client\com_lightstreamer_client.py:1887 in __init__
    super().__init__()


  File ~\anaconda3\envs\Economic\lib\site-packages\lightstreamer_client\com_lightstreamer_client.py:1781 in __init__
    haxe_Log.trace((("[" + Std.string(self)) + "] instantiated."),_hx_AnonObject({'fileName': "hx/concurrent/Service.hx", 'lineNumber': 56, 'className': "hx.concurrent.ServiceBase", 'methodName': "new"}))


  File ~\anaconda3\envs\Economic\lib\site-packages\lightstreamer_client\com_lightstreamer_client.py:2316 in _hx_local_0
    python_Lib.printString((("" + Std.string(haxe_Log.formatOutput(v,infos))) + HxOverrides.stringOrNull(python_Lib.lineEnd)))


  File ~\anaconda3\envs\Economic\lib\site-packages\lightstreamer_client\com_lightstreamer_client.py:1687 in printString
    python_lib_Sys.stdout.buffer.write(_hx_str.encode("utf-8", "strict"))


AttributeError: 'TTYOutStream' object has no attribute 'buffer'
Hello,


Unfortunately, we have no experience with Anaconda and Spyder IDE.
Can you suggest what tools we need to install to reproduce your environment?
Hello and thanks,

Anaconda distribution with Spyder and Command prompt installed.
Perform a regular pip install of the lightstreamer library through the command prompt in Anaconda.
In Spyder, enter "from lightstreamer_client import *" (depending on version you may need to say lightstreamer.client or lightstreamer_client)
you will reproduce the error above.

Thanks!
The error is from a third-party library used by the Lightstreamer Python Client, which tries to print some logs to the virtual console of the Spyder IDE. It seems that this console has some limitations with respect to the standard console. Indeed if you run the same code from the Anaconda Prompt, the Client works as expected.


If possible, I’ll try to fix this issue in a next release of the SDK, but in the meantime my advice is to write your program with Spyder but to run it only from the Anaconda Prompt.
13 days later
Thanks for the update, but it doesn't work from the command line, in Jupyter Notebook, or in Spyder. Would I find out about the new version from github?
Thanks!
Have you tried to run your script from the Anaconda Prompt?

To open Anaconda Prompt:

- Windows: Click Start, search for Anaconda Prompt, and click to open.
- macOS: Use Cmd+Space to open Spotlight Search and type “Navigator” to open the program.
- Linux: Open Applications > System Tools > terminal.

You can find further details here.

Anyway I’m working on the new version of the Client lib, which I hope could resolve the issue.
6 days later
Thanks, I did a reinstall and got this:

Traceback (most recent call last):


File ~\anaconda3\envs\light_streamer\lib\site-packages\aiohttp\client_reqrep.py:70
import cchardet as chardet


ModuleNotFoundError: No module named 'cchardet'




During handling of the above exception, another exception occurred:


Traceback (most recent call last):


Cell In[2], line 1
from lightstreamer.client import *


File ~\anaconda3\envs\light_streamer\lib\site-packages\lightstreamer\client\__init__.py:2
from .ls_python_client_wrapper import *


File ~\anaconda3\envs\light_streamer\lib\site-packages\lightstreamer\client\ls_python_client_wrapper.py:2
from .ls_python_client_haxe import LSConsoleLoggerProvider, LSConsoleLogLevel, LSProxy, LSSubscription, LSConnectionDetails, LSConnectionOptions, LSLightstreamerClient


File ~\anaconda3\envs\light_streamer\lib\site-packages\lightstreamer\client\ls_python_client_haxe.py:10
from .com_lightstreamer_net import CookieHelper as com_lightstreamer_internal_CookieHelper


File ~\anaconda3\envs\light_streamer\lib\site-packages\lightstreamer\client\com_lightstreamer_net.py:1
import aiohttp


File ~\anaconda3\envs\light_streamer\lib\site-packages\aiohttp\__init__.py:6
from .client import (


File ~\anaconda3\envs\light_streamer\lib\site-packages\aiohttp\client.py:59
from .client_reqrep import (


File ~\anaconda3\envs\light_streamer\lib\site-packages\aiohttp\client_reqrep.py:72
import charset_normalizer as chardet # type: ignore[no-redef]


File ~\anaconda3\envs\light_streamer\lib\site-packages\charset_normalizer\__init__.py:23
from charset_normalizer.api import from_fp, from_path, from_bytes, normalize


File ~\anaconda3\envs\light_streamer\lib\site-packages\charset_normalizer\api.py:10
from charset_normalizer.md import mess_ratio


File charset_normalizer\md.py:5
from charset_normalizer.utils import is_punctuation, is_symbol, unicode_range, is_accentuated, is_latin, \


ImportError: cannot import name 'COMMON_SAFE_ASCII_CHARACTERS' from 'charset_normalizer.constant' (C:\Users\frank\anaconda3\envs\light_streamer\lib\site-packages\charset_normalizer\constant.py)

It seems a problem related to aiohttp, a library used by the Lightstreamer Client to make http and websocket connections.
I really don’t know why it happens but you can try the workaround suggested in this SO post.
OK, I asked chatGPT and it told me to:
pip install cchardet
- it worked!