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

RuntimeError: Could not find libmono #254

Closed sensharma closed 2 years ago

sensharma commented 2 years ago

The problem

Using python 3.9 and stock-indicators v0.8.1, installed using pip on Ubuntu 20.04, I get

Error message(s):

RuntimeError: Could not find libmono

The problem seems to originate from pythonnet (pip automatically installs v3.0.0a1 for me). Traceback below.

To Reproduce

Simply using import statements such as import stock_indicators or from stock_indicators.indicators.common.quote import Quote

Full traceback:

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

File ~/miniconda3/envs/trading/lib/python3.9/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 ~/miniconda3/envs/trading/lib/python3.9/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 ~/miniconda3/envs/trading/lib/python3.9/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 ~/miniconda3/envs/trading/lib/python3.9/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 ~/miniconda3/envs/trading/lib/python3.9/site-packages/pythonnet/__init__.py:36, in load()
     31 from os.path import join, dirname
     33 if _RUNTIME is None:
     34     # TODO: Warn, in the future the runtime must be set explicitly, either
     35     # as a config/env variable or via set_runtime
---> 36     set_default_runtime()
     38 dll_path = join(dirname(__file__), "runtime", "Python.Runtime.dll")
     40 _LOADER_ASSEMBLY = _RUNTIME.get_assembly(dll_path)

File ~/miniconda3/envs/trading/lib/python3.9/site-packages/pythonnet/__init__.py:22, in set_default_runtime()
     20     set_runtime(clr_loader.get_netfx())
     21 else:
---> 22     set_runtime(clr_loader.get_mono())

File ~/miniconda3/envs/trading/lib/python3.9/site-packages/clr_loader/__init__.py:21, in get_mono(domain, config_file, global_config_file, libmono, sgen, debug, jit_options)
     18 from .mono import Mono
     20 if libmono is None:
---> 21     libmono = find_libmono(sgen)
     23 impl = Mono(
     24     domain=domain,
     25     debug=debug,
   (...)
     29     libmono=libmono,
     30 )
     31 return Runtime(impl)

File ~/miniconda3/envs/trading/lib/python3.9/site-packages/clr_loader/util/find.py:67, in find_libmono(sgen)
     64     path = find_library(unix_name)
     66 if path is None:
---> 67     raise RuntimeError("Could not find libmono")
     69 return path

RuntimeError: Could not find libmono
LeeDongGeon1996 commented 2 years ago

@sensharma Thank you for detail report. Because we have dependency on pythonnet, you have to make sure that you have CLR runtime on your machine.

You can download from here:

sensharma commented 2 years ago

@LeeDongGeon1996 Hi, I first installed the ASP.NET runtime as per instructions here, following from the link you provided. When that did not work, I installed the full .NET sdk. Also tried uninstalling and re-installing stock-indicators after installing the runtime and sdk. But I keep getting the same error. What am I missing? Thanks.

Current dotnet --info output below

.NET SDK (reflecting any global.json):
 Version:   6.0.400
 Commit:    7771abd614

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  20.04
 OS Platform: Linux
 RID:         ubuntu.20.04-x64
 Base Path:   /usr/share/dotnet/sdk/6.0.400/

global.json file:
  Not found

Host:
  Version:      6.0.8
  Architecture: x64
  Commit:       55fb7ef977

.NET SDKs installed:
  6.0.400 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.8 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.8 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Download .NET:
  https://aka.ms/dotnet-download

Learn about .NET Runtimes and SDKs:
  https://aka.ms/dotnet/runtimes-sdk-info
sensharma commented 2 years ago

Ok, I have managed to sort this issue out by installing pythonnet separately using conda as mentioned here, before installing stock-indicators using pip.

This automatically installs mono within the virtual environment. No .NET runtime/sdk required separately. pip dependencies, either for stock-indicators or pythonnet, are not properly defined.

This step should definitely find mention in Installation and setup.

Closing this issue.