microsoft / qlib

Qlib is an AI-oriented quantitative investment platform that aims to realize the potential, empower research, and create value using AI technologies in quantitative investment, from exploring ideas to implementing productions. Qlib supports diverse machine learning modeling paradigms. including supervised learning, market dynamics modeling, and RL.
https://qlib.readthedocs.io/en/latest/
MIT License
15.47k stars 2.64k forks source link

ModuleNotFoundError: No module named 'qlib.config' #96

Closed ardeal closed 1 year ago

ardeal commented 3 years ago

Both on Windows and Linux, when I run the command: python run_all_model.py --models=lightgbm, I got the following error message:

Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'qlib.config'
you-n-g commented 3 years ago

@ardeal Did you install qlib by python setup.py install?

ardeal commented 3 years ago

I firstly installed it by command python setup.py install, and encountered the issue.

secondly, I run command pip uninstall qlib to uninstall it, and then run command pip install qlib to install it. I encountered the same issue.

aleeusgr commented 3 years ago

Installing into a clean env solved the issue for me

ardeal commented 3 years ago

Installing into a clean env might be a solution, but I don't think it is a perfect solution. There might be something wrong with the repo.

you-n-g commented 3 years ago

@ardeal I can't reproduce your error. Could you provide more details to reproduce this bug? Thanks

ardeal commented 3 years ago

@you-n-g On Linux: Ubuntu 16.04, python 3.6.9, I tried both ways: 1) pip install qlib 2) pip uninstall qlib && python setup.py install then I copy the file run_all_model.py to an empty folder and then run command: python run_all_model.py --models=lightgbm

I got the following error:

Traceback (most recent call last):
  File "run_all_model.py", line 24, in <module>
    from qlib.config import REG_CN
ModuleNotFoundError: No module named 'qlib.config'

On windows 10, my python is 3.8.5 which is installed by anaconda. I repeated similar steps on anaconda prompt, and got the same error.

aleeusgr commented 3 years ago

@ardeal
If I understand right, this library is under construction. You might wait for the issue to resolve, or you can participate to help. If installing into a clean env resolves the issue, this info might help devs pin the location of the error faster. Alternatively, the log of the installation script might provide some useful info.

you-n-g commented 3 years ago

@ardeal I see now. qlib on pypi is another project. Our project name on pypi is pyqlib . Please clean https://pypi.org/project/qlib/ completely and install qlib by pip install pyqlib

We wish we could register qlib earlier. LOL

Thanks.

ardeal commented 3 years ago

I run command: pip uninstall qlib and then pip install pyqlib. then run in an empty folder: python run_all_model.py --models=lightgbm

I got the following error message:

python run_all_model.py --models=lightgbm
C:\ProgramData\Anaconda3\lib\site-packages\win32\lib\pywintypes.py:2: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp, sys, os
[18112:MainThread](2020-12-14 16:29:02,464) INFO - qlib.Initialization - [__init__.py:42] - default_conf: client.
[18112:MainThread](2020-12-14 16:29:04,478) WARNING - qlib.Initialization - [__init__.py:57] - redis connection failed(host=127.0.0.1 port=6379), cache will not be used!
[18112:MainThread](2020-12-14 16:29:04,478) INFO - qlib.Initialization - [__init__.py:77] - qlib successfully initialized based on client settings.
[18112:MainThread](2020-12-14 16:29:04,479) INFO - qlib.Initialization - [__init__.py:80] - data_path=C:\Users\Ardeal\.qlib\qlib_data\cn_data
[18112:MainThread](2020-12-14 16:29:04,479) ERROR - qlib.workflow - [utils.py:35] - An exception has been raised[AttributeError: module 'signal' has no attribute 'SIGTSTP'].
  File "run_all_model.py", line 72, in <module>
    signal.signal(signal.SIGTSTP, handler)
AttributeError: module 'signal' has no attribute 'SIGTSTP'

moreover:

pip install -U signal
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
ERROR: Could not find a version that satisfies the requirement signal
ERROR: No matching distribution found for signal
you-n-g commented 3 years ago

@ardeal This singal.SIGTSTP does not work on windows. We'll fix it later. Thanks for reporting.

you-n-g commented 3 years ago

@ardeal
The singal.SIGTSTP issue has been fixed and merged. You can try again now. :) https://github.com/microsoft/qlib/pull/118

ardeal commented 3 years ago

after pulling the latest code from github, I could run the code on Linux correctly.

however, if I run the following command in order on Windows 10: python scripts/get_data.py qlib_data --target_dir ../qlib_data/cn_data --region cn qrun benchmarks/LightGBM/workflow_config_lightgbm_Alpha158.yaml

the code couldn't find the data dir as the default data dir in your code is ~/.qlib....

Derek-Wds commented 3 years ago

Hi @ardeal , if you want to run the workflow with qrun with a different data path, it is recommended to change the provider_uri in the yaml file such as workflow_config_lightgbm_Alpha158.yaml manully for now.

Another option would be running the workflow with workflow_by_code.py under the examples folder, where the provider_uri should be modified accordingly as well.

We are sorry that Qlib is not supporting multi-platform in a decent way. We will try to make it more convenient for users to run models directly on different OS in the near future.

Thanks.

ardeal commented 3 years ago

I did the following steps: python scripts/get_data.py qlib_data --target_dir ../qlib_data/cn_data --region cn I changed the provider_uri qrun benchmarks/LightGBM/workflow_config_lightgbm_Alpha158.yaml

and got the following error message: WARN: data not found for SH600004.vwap WARN: data not found for SH600010.vwap WARN: data not found for SH600016.vwap WARN: data not found for SH600028.vwap WARN: data not found for SH600025.vwap WARN: data not found for SH600011.vwap

image

ardeal commented 3 years ago

If I run the file: workflow_by_code.py on windows 10, I got the following error message:

Do not import qlib package in the repository directory!
python-BaseException
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\doc\code_python\dl_framework\qlib\qlib\contrib\model\gbdt.py", line 8, in <module>
    from ...model.base import ModelFT
  File "C:\doc\code_python\dl_framework\qlib\qlib\model\__init__.py", line 6, in <module>
    from .base import Model
  File "C:\doc\code_python\dl_framework\qlib\qlib\model\base.py", line 5, in <module>
    from ..data.dataset import Dataset
  File "C:\doc\code_python\dl_framework\qlib\qlib\data\__init__.py", line 8, in <module>
    from .data import (
  File "C:\doc\code_python\dl_framework\qlib\qlib\data\data.py", line 21, in <module>
    from .cache import H
  File "C:\doc\code_python\dl_framework\qlib\qlib\data\cache.py", line 35, in <module>
    from .ops import *
  File "C:\doc\code_python\dl_framework\qlib\qlib\data\ops.py", line 18, in <module>
    from ._libs.rolling import rolling_slope, rolling_rsquare, rolling_resi
ModuleNotFoundError: No module named 'qlib.data._libs.rolling'
you-n-g commented 3 years ago

@ardeal Please notice the first line of output "Do not import qlib package in the repository directory!" I've make the message more noticeable now. https://github.com/microsoft/qlib/blob/main/qlib/data/ops.py#L22

ardeal commented 3 years ago

in both cases running qrun or copying workflow_by_code.py to an empty folder and then run, I am experiencing the same issue:

[5012:MainThread](2020-12-16 10:35:58,808) INFO - qlib.Initialization - [__init__.py:42] - default_conf: client.
[5012:MainThread](2020-12-16 10:36:00,839) WARNING - qlib.Initialization - [__init__.py:57] - redis connection failed(host=127.0.0.1 port=6379), cache will not be used!
[5012:MainThread](2020-12-16 10:36:00,839) INFO - qlib.Initialization - [__init__.py:77] - qlib successfully initialized based on client settings.
[5012:MainThread](2020-12-16 10:36:00,840) INFO - qlib.Initialization - [__init__.py:80] - data_path=C:\doc\code_python\dl_framework\qlib_data\cn_data
WARN: data not found for SH600009.vwap
WARN: data not found for SH600000.vwap
ardeal commented 3 years ago

The reason why the code couldn't be run in the repo dir might be that: relative path such as: .data._libs.rolling should not be used in python code, alternatively, the path data._libs.rolling should work.

@ardeal Please notice the first line of output "Do not import qlib package in the repository directory!" I've make the message more noticeable now. https://github.com/microsoft/qlib/blob/main/qlib/data/ops.py#L22

you-n-g commented 3 years ago

@ardeal

  1. The reason that the code couldn't run in the repo dir is that we should complile .pyx file with cython before using qlib/data/_libs/rolling.pyx. If we import qlib from the repository folder instead of the folder installed by python setup.py install, the compiling steps are skipped.

  2. WARN: data not found for SH600009.vwap indicates that we have no vwap in our data. We didn't include vwap in our database because there are not public vwap data in the public data source. In our examples, we use close instead.

jerryldh commented 3 years ago

@you-n-g On Linux: Ubuntu 16.04, python 3.6.9, I tried both ways:

  1. pip install qlib
  2. pip uninstall qlib && python setup.py install then I copy the file run_all_model.py to an empty folder and then run command: python run_all_model.py --models=lightgbm

I got the following error:

Traceback (most recent call last):
  File "run_all_model.py", line 24, in <module>
    from qlib.config import REG_CN
ModuleNotFoundError: No module named 'qlib.config'

On windows 10, my python is 3.8.5 which is installed by anaconda. I repeated similar steps on anaconda prompt, and got the same error.

i got the same error here is my solution: run the script in your IDE

niurencheng commented 3 years ago

(Rl) D:\pythonProject\qlib>python examples/run_all_model.py --models=lightgbm Traceback (most recent call last): File "examples/run_all_model.py", line 39, in GetData().qlib_data(target_dir=provider_uri, region=REG_CN, exists_skip=True) TypeError: qlib_data() got an unexpected keyword argument 'exists_skip'

thanks

you-n-g commented 3 years ago

@niurencheng Are you using the latest version of Qlib? The exists_skip is in the parameters list. https://github.com/microsoft/qlib/blob/55b6ff123e6044074489710f96e991e091526087/qlib/tests/data.py#L116