Repository: freqtrade/freqtrade

Issue:
RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd
<!-- 
Have you searched for similar issues before posting it?

If you have discovered a bug in the bot, please [search our issue tracker](https://github.com/freqtrade/freqtrade/issues?q=is%3Aissue). 
If it hasn't been reported, please create a new issue.

Please do not use bug reports to request new features.
-->

## Describe your environment

Debian 10
Python 3.7.3 (default, Jul 25 2020, 13:03:44) 
ccxt==1.40.99
freqtrade develop-16dad8b6
numpy                   1.19.5

  
Note: All issues other than enhancement requests will be closed without further comment if the above template is deleted or not filled out.

## Describe the problem:

*Explain the problem you have encountered*

### Steps to reproduce:

Newly done installation, on new system, performed with `./script.sh -i` method
questions were answered during installation as follows:
-y
dev:-y
plot:-n
hyperopt:-n


`freqtrade trade --config config.json --strategy SampleStrategy` fails to start

`RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd`

```
RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd
2021-01-30 22:02:55,644 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
  File "/root/freqtrade/freqtrade/main.py", line 37, in main
    return_code = args['func'](args)
  File "/root/freqtrade/freqtrade/commands/trade_commands.py", line 13, in start_trading
    from freqtrade.worker import Worker
  File "/root/freqtrade/freqtrade/worker.py", line 15, in <module>
    from freqtrade.freqtradebot import FreqtradeBot
  File "/root/freqtrade/freqtrade/freqtradebot.py", line 19, in <module>
    from freqtrade.edge import Edge
  File "/root/freqtrade/freqtrade/edge/__init__.py", line 1, in <module>
    from .edge_positioning import Edge, PairInfo  # noqa: F401
  File "/root/freqtrade/freqtrade/edge/edge_positioning.py", line 8, in <module>
    import utils_find_1st as utf1st
  File "/root/freqtrade/.env/lib/python3.7/site-packages/utils_find_1st/__init__.py", line 3, in <module>
    from .find_1st import find_1st
ImportError: numpy.core.multiarray failed to import
```





Discussion:
`pip install numpy --upgrade` works, something has to be updated in the files, when you figure out what, could you tell me please, thanks
it would appear that numpy is up and downgraded during installation.

The logs during the installation should tell if that's happening - i suspect it's a pinned install-dep version on find_1st (it has numpy as install dependency, so numpy MUST be installed before it's installed).
So if they pin the version on install, but not on run, numpy might be installed twice, first a older version, then a newer one.

Yup, same problem. Searched for about 2 hours and found nothing...

```
(.env) fusseldieb@home-nuc:~/freqtrade$ freqtrade trade --config config.json --strategy SampleStrategy
RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd
2021-01-31 09:24:40,898 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
  File "/home/fusseldieb/freqtrade/freqtrade/main.py", line 37, in main
    return_code = args['func'](args)
  File "/home/fusseldieb/freqtrade/freqtrade/commands/trade_commands.py", line 13, in start_trading
    from freqtrade.worker import Worker
  File "/home/fusseldieb/freqtrade/freqtrade/worker.py", line 15, in <module>
    from freqtrade.freqtradebot import FreqtradeBot
  File "/home/fusseldieb/freqtrade/freqtrade/freqtradebot.py", line 19, in <module>
    from freqtrade.edge import Edge
  File "/home/fusseldieb/freqtrade/freqtrade/edge/__init__.py", line 1, in <module>
    from .edge_positioning import Edge, PairInfo  # noqa: F401
  File "/home/fusseldieb/freqtrade/freqtrade/edge/edge_positioning.py", line 8, in <module>
    import utils_find_1st as utf1st
  File "/home/fusseldieb/freqtrade/.env/lib/python3.8/site-packages/utils_find_1st/__init__.py", line 3, in <module>
    from .find_1st import find_1st
ImportError: numpy.core.multiarray failed to import
(.env) fusseldieb@home-nuc:~/freqtrade$

```
@Fusseldieb what's your numpy version (`pip freeze | grep numpy`) ? 

after that, please try `pip install -U numpy` - and post the output of this here (and also if it works after running this).

Resolving patch:
diff --git a/freqtrade/data/btanalysis.py b/freqtrade/data/btanalysis.py
--- a/freqtrade/data/btanalysis.py
+++ b/freqtrade/data/btanalysis.py
@@ -312,7 +312,7 @@ def calculate_market_change(data: Dict[str, pd.DataFrame], column: str = "close"
         end = df[column].dropna().iloc[-1]
         tmp_means.append((end - start) / start)
 
-    return np.mean(tmp_means)
+    return float(np.mean(tmp_means))
 
 
 def combine_dataframes_with_mean(data: Dict[str, pd.DataFrame],
diff --git a/freqtrade/misc.py b/freqtrade/misc.py
--- a/freqtrade/misc.py
+++ b/freqtrade/misc.py
@@ -9,7 +9,6 @@
 from typing import Any
 from typing.io import IO
 
-import numpy as np
 import rapidjson
 
 
@@ -28,20 +27,6 @@ def shorten_date(_date: str) -> str:
     return new_date
 
 
-############################################
-# Used by scripts                          #
-# Matplotlib doesn't support ::datetime64, #
-# so we need to convert it into ::datetime #
-############################################
-def datesarray_to_datetimearray(dates: np.ndarray) -> np.ndarray:
-    """
-    Convert an pandas-array of timestamps into
-    An numpy-array of datetimes
-    :return: numpy-array of datetime
-    """
-    return dates.dt.to_pydatetime()
-
-
 def file_dump_json(filename: Path, data: Any, is_zip: bool = False, log: bool = True) -> None:
     """
     Dump JSON data into a file
diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py
--- a/freqtrade/rpc/rpc.py
+++ b/freqtrade/rpc/rpc.py
@@ -378,7 +378,7 @@ def _rpc_trade_statistics(
 
         # Prepare data to display
         profit_closed_coin_sum = round(sum(profit_closed_coin), 8)
-        profit_closed_ratio_mean = mean(profit_closed_ratio) if profit_closed_ratio else 0.0
+        profit_closed_ratio_mean = float(mean(profit_closed_ratio) if profit_closed_ratio else 0.0)
         profit_closed_ratio_sum = sum(profit_closed_ratio) if profit_closed_ratio else 0.0
 
         profit_closed_fiat = self._fiat_converter.convert_amount(
@@ -388,7 +388,7 @@ def _rpc_trade_statistics(
         ) if self._fiat_converter else 0
 
         profit_all_coin_sum = round(sum(profit_all_coin), 8)
-        profit_all_ratio_mean = mean(profit_all_ratio) if profit_all_ratio else 0.0
+        profit_all_ratio_mean = float(mean(profit_all_ratio) if profit_all_ratio else 0.0)
         profit_all_ratio_sum = sum(profit_all_ratio) if profit_all_ratio else 0.0
         profit_all_fiat = self._fiat_converter.convert_amount(
             profit_all_coin_sum,


Test patch:
diff --git a/tests/test_misc.py b/tests/test_misc.py
--- a/tests/test_misc.py
+++ b/tests/test_misc.py
@@ -6,11 +6,9 @@
 
 import pytest
 
-from freqtrade.data.converter import ohlcv_to_dataframe
-from freqtrade.misc import (datesarray_to_datetimearray, file_dump_json, file_load_json,
-                            format_ms_time, pair_to_filename, plural, render_template,
-                            render_template_with_fallback, safe_value_fallback,
-                            safe_value_fallback2, shorten_date)
+from freqtrade.misc import (file_dump_json, file_load_json, format_ms_time, pair_to_filename,
+                            plural, render_template, render_template_with_fallback,
+                            safe_value_fallback, safe_value_fallback2, shorten_date)
 
 
 def test_shorten_date() -> None:
@@ -19,22 +17,6 @@ def test_shorten_date() -> None:
     assert shorten_date(str_data) == str_shorten_data
 
 
-def test_datesarray_to_datetimearray(ohlcv_history_list):
-    dataframes = ohlcv_to_dataframe(ohlcv_history_list, "5m", pair="UNITTEST/BTC",
-                                    fill_missing=True)
-    dates = datesarray_to_datetimearray(dataframes['date'])
-
-    assert isinstance(dates[0], datetime.datetime)
-    assert dates[0].year == 2017
-    assert dates[0].month == 11
-    assert dates[0].day == 26
-    assert dates[0].hour == 8
-    assert dates[0].minute == 50
-
-    date_len = len(dates)
-    assert date_len == 2
-
-
 def test_file_dump_json(mocker) -> None:
     file_open = mocker.patch('freqtrade.misc.open', MagicMock())
     json_dump = mocker.patch('rapidjson.dump', MagicMock())