facioquo / stock-indicators-python

Stock Indicators for Python. Maintained by @LeeDongGeon1996
https://python.StockIndicators.dev
Apache License 2.0
220 stars 37 forks source link

'Assembly' object is not subscriptable error importing "indicators" #282

Closed fede72bari closed 1 year ago

fede72bari commented 1 year ago

The problem

I have installed stock_indicators using pip from jupyter/anaconda environment and the installation ended successfully. Regretfully, when I try to import "indicators" I got an error. The attempts to restart the kernel and restart the full anaconda environment after the library installation have been unsuccessful.

PS: repeated all the installation operations by the command line. Nothing changed.

Error message(s):

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [12], in <cell line: 1>()
----> 1 from stock_indicators import indicators

File ~\anaconda3\lib\site-packages\stock_indicators\__init__.py:17, in <module>
      1 """
      2 Stock Indicators for Python
      3 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
   (...)
     14 library. A Stock Indicators for .NET is also available.
     15 """
---> 17 from stock_indicators import indicators
     18 from stock_indicators.indicators.common import *

File ~\anaconda3\lib\site-packages\stock_indicators\indicators\__init__.py:3, in <module>
      1 """All available APIs for calculating indicators."""
----> 3 from stock_indicators import _cslib
      5 from .adl import (get_adl)
      6 from .adx import (get_adx)

File ~\anaconda3\lib\site-packages\stock_indicators\_cslib\__init__.py:12, in <module>
      1 """
      2 Skender.Stock.Indicators
      3 ~~~~~~~~~~~~~~~~~~~~~~~~
   (...)
      8 It is currently using `.NET Standard 2.1`.
      9 """
     11 import os
---> 12 import clr
     14 skender_stock_indicators_dll_path = os.path.join(
     15     os.path.dirname(__file__),
     16     "lib/Skender.Stock.Indicators.dll"
     17 )
     18 clr.AddReference(skender_stock_indicators_dll_path)

File ~\anaconda3\lib\site-packages\clr.py:6, in <module>
      1 """
      2 Legacy Python.NET loader for backwards compatibility
      3 """
      5 from pythonnet import load
----> 6 load()

File ~\anaconda3\lib\site-packages\pythonnet\__init__.py:42, in load()
     38 dll_path = join(dirname(__file__), "runtime", "Python.Runtime.dll")
     40 _LOADER_ASSEMBLY = _RUNTIME.get_assembly(dll_path)
---> 42 func = _LOADER_ASSEMBLY["Python.Runtime.Loader.Initialize"]
     43 if func(''.encode("utf8")) != 0:
     44     raise RuntimeError("Failed to initialize Python.Runtime.dll")

TypeError: 'Assembly' object is not subscriptable

To Reproduce

In jupyter

pip install stock-indicators [restart kernel, anaconda, PC, everything] from stock_indicators import indicators

DaveSkender commented 1 year ago

May be related to #277 @LeeDongGeon1996 I saw some work you were doing for vNext, are we changing how we’re handling dependencies?

fede72bari commented 1 year ago

before i downgrade something that could badly affect other parts of my code, may I ask which possible cause appear to be similar to the case you have mentioned? I am a beginner, but the final parts of the two errors appear to be very different to me. In this one no mention of "Mono" and in the other one no mention of "func = _LOADER_ASSEMBLY["Python.Runtime.Loader.Initialize"]" and no mention to "TypeError: 'Assembly' object is not subscriptable"

LeeDongGeon1996 commented 1 year ago

On version <=0.8.1, We support Mono and .NET runtime both and we have dependency on pythonnet to achieve it. pythonnet uses internally clr-loader to load clr, such as .NET runtime or Mono. Depend on which your system is, clr-loader tries to load default CLR(e.g. default clr on Linux is Mono). How they load various CLR is abstracted by them. Anyway, clr-loader had been updated to v0.2.3 and it is compatible only with latest pythonnet(>=3.0.0.post1). The error msg you've got is from incompatibility between legacy pythonnet(3.0.0a1) and the latest clr-loader. More detail about error message is the problem about how they load clr by system, so it'd be better to ask to pythonnet.

LeeDongGeon1996 commented 1 year ago

FYI, probably in the next week we are going to release official stock-indicators for python v1.0.0. And it supports only .NET6 and dropped Mono support. It is much more reliable and faster than now.

traderblakeq commented 1 year ago

got same issue

traderblakeq commented 1 year ago

pip install pythonnet -U

Solved it for me.

LeeDongGeon1996 commented 1 year ago

@traderblakeq Thanks for your helpful comment :)