can't import external module while creating nvda add-on


Abhishek Raut
 

I am creating add-on where some external modules required.

Following way I used to import external module:

I have copied the lib from site packages

After that, created directory in globalPlugins and, by following code I have imported:

 

```

import sys

sys.path.append(os.path.dirname(__file__))

import enchant

sys.path.remove(os.path.dirname(__file__))

```

 

I have uninstall module, and run same script in another directory, and there it has imported successfully.

But here, its giving error.

Error:

Traceback (most recent call last):

  File "globalPluginHandler.pyc", line 23, in listPlugins

  File "importlib\init.pyc", line 127, in import_module

  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import

  File "<frozen importlib._bootstrap>", line 983, in _find_and_load

  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked

  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked

  File "<frozen importlib._bootstrap_external>", line 728, in exec_module

  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed

  File "C:\Users\abhishek\AppData\Roaming\nvda\addons\spell_checker\globalPlugins\spell_checker\init.py", line 4, in <module>

    from .spellcheck import spellcheck

  File "C:\Users\abhishek\AppData\Roaming\nvda\addons\spell_checker\globalPlugins\spell_checker\spellcheck.py", line 5, in <module>

    from . import enchant

  File "C:\Users\abhishek\AppData\Roaming\nvda\addons\spell_checker\globalPlugins\spell_checker\enchant\init.py", line 81, in <module>

    from enchant import _enchant as _e

  File "C:\Users\abhishek\AppData\Roaming\nvda\addons\spell_checker\globalPlugins\spell_checker\enchant\init.py", line 81, in <module>

    from enchant import _enchant as _e

  File "C:\Users\abhishek\AppData\Roaming\nvda\addons\spell_checker\globalPlugins\spell_checker\enchant\_enchant.py", line 157, in <module>

    raise ImportError(msg)

ImportError: The 'enchant' C library was not found and maybe needs to be installed.

See  https://pyenchant.github.io/pyenchant/install.html

for details