The problem is that NVDA itself includes some (but not all) modules in
the xml package. This means that NVDA's copy of the xml package will
take precedence. You should be able to do something like this before
what you're already doing:
import xml
xml.__path__.append(os.path.join(PLUGIN_DIR, "lib", "xml"))
This makes Python search your copy of the xml package when looking for
modules in the xml package.
Jamie
On 30/07/2015 7:26 PM, Hrvoje Katić wrote:
Hi all,
I'm working on a new addon that will download youtube videos and save them into chosen video or audio format automatically with a single keystroke. It works as follows: You open a URL with a video, press nvda+shift+y and ther URL will be autodetected and the download begins automatically, so you can download while listening video with no need to paste url or switch to another window.
To achieve this, I'm using youtube_dl which works both as a single app and a Python module. I don't wanna run it as an app, because it'll pop-up command prompt while downloading, and also I'll not be able to catch exceptions that may eventually happen, so I'm running it as a Python module. Unfortunately, youtube_dl uses some python modules not included with NVDA by default, so I copied manually all required external modules from python27/lib into a lib subfolder inside the globalPlugin's folder, and I added this subfolder to the sys.path inside the addon's __init__.py as follows:PLUGIN_DIR = os.path.dirname(__file__)This allowed youtube_dl to import all required modules including urllib2, json and others, but the problem begins when it comes to import xml.etree.ElementTree. Here's what I get when i open log viewer:
sys.path.append(os.path.join(PLUGIN_DIR, "lib"))
import youtube_dl
del sys.path[-1]
ERROR - globalPluginHandler.listPlugins (11:06:50):So, the utils.py submodule of youtube_dl cannot find xml.etree, although I've double checked that xml folder is copied properly with all the subfolders.
Error importing global plugin youtube
Traceback (most recent call last):
File "globalPluginHandler.pyc", line 22, in listPlugins
File "C:\Users\pc3\AppData\Roaming\nvda\addons\Youtube\globalPlugins\youtube\__init__.py", line 31, in <module>
File "C:\Users\pc3\AppData\Roaming\nvda\addons\Youtube\globalPlugins\youtube\youtube_dl\__init__.py", line 16, in <module>
File "C:\Users\pc3\AppData\Roaming\nvda\addons\Youtube\globalPlugins\youtube\youtube_dl\options.py", line 8, in <module>
File "C:\Users\pc3\AppData\Roaming\nvda\addons\Youtube\globalPlugins\youtube\youtube_dl\downloader\__init__.py", line 3, in <module>
File "C:\Users\pc3\AppData\Roaming\nvda\addons\Youtube\globalPlugins\youtube\youtube_dl\downloader\common.py", line 9, in <module>
File "C:\Users\pc3\AppData\Roaming\nvda\addons\Youtube\globalPlugins\youtube\youtube_dl\utils.py", line 32, in <module>
ImportError: No module named etree.ElementTree
I tried to fix this in many ways, so I really have no more ideas on how to get all external submodules imported properly when running the plugin.
Thanks for any help!