0

Can anyone help with this error?

I verified in Anaconda Navigator that quantlib-python (1.14) is installed.


import QuantLib as ql
Traceback (most recent call last):

  File "<ipython-input-11-b9e27c0bb1fd>", line 1, in <module>
    import QuantLib as ql

  File "C:\Anaconda3\lib\site-packages\QuantLib\__init__.py", line 21, in <module>
    from .QuantLib import *

  File "C:\Anaconda3\lib\site-packages\QuantLib\QuantLib.py", line 17, in <module>
    _QuantLib = swig_import_helper()

  File "C:\Anaconda3\lib\site-packages\QuantLib\QuantLib.py", line 16, in swig_import_helper
    return importlib.import_module('_QuantLib')

  File "C:\Anaconda3\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)

ModuleNotFoundError: No module named '_QuantLib'

Thanks for the help, Dave

Red
  • 26,798
  • 7
  • 36
  • 58
mapesd
  • 31
  • 2
  • Does this answer your question? [python 3.6: No module named \_QuantLib after installation of QuantLib and QuantLib-SWIG](https://stackoverflow.com/questions/45539869/python-3-6-no-module-named-quantlib-after-installation-of-quantlib-and-quantli) – Red Jul 03 '20 at 19:56

1 Answers1

0

Packages and modules in python can be imported when they appear in the PYTHONPATH environement variable or in the sys.path list.

On each PYTHONPATH expanding, will ends up in the sys.path list.

so make sure that, the instalation of your module was successeful and its path exist in the sys.path list. how you check? see below:

in comand line or in script.py type:

import sys
p=r'C:\Users\AppData\Local\Programs\Python\Python38\lib\QuantLib'
if p not in sys.path:
    print('QuantLib not in the sys path list!')
    sys.path.append(p)  #we add it to sys path now we can import it

its better to append new paths to the PYTHONPATH rather than editing the sys.path. Anywa, if the module you are trying to import (QuantLib) is a built in lib/module you should check if the pyhton installation was successful and the path environement variable edited correctly and has all paths that should be.

Adam
  • 2,820
  • 1
  • 13
  • 33