Repository: Flexget/Flexget

Issue:
Flexget crashes due to "No module named 'packaging'"
### Expected behaviour:

daemon starts 

### Actual behaviour:
flexget crashes

### Steps to reproduce:
flexget daemon start -d

  
#### Log:
```
    self.initialize()
    |    -> <function Manager.initialize at 0x7fceb0a4d950>
    -> <flexget.manager.Manager object at 0x7fceb204add8>
  File "/home/loke/.psources/flexget/lib/python3.7/site-packages/flexget/manager.py", line 215, in initialize
    extra_components=[os.path.join(self.config_base, 'components')],
                      |  |    |    |    -> '/home/loke/.flexget'
                      |  |    |    -> <flexget.manager.Manager object at 0x7fceb204add8>
                      |  |    -> <function join at 0x7fceb2c67ea0>
                      |  -> <module 'posixpath' from '/home/loke/.psources/flexget/lib/python3.7/posixpath.py'>
                      -> <module 'os' from '/home/loke/.psources/flexget/lib/python3.7/os.py'>
  File "/home/loke/.psources/flexget/lib/python3.7/site-packages/flexget/plugin.py", line 555, in load_plugins
    _load_plugins_from_dirs(extra_plugins)
    |                       -> ['/home/loke/.flexget/plugins', '/home/loke/.psources/flexget/lib/python3.7/site-packages/flexget/plugins']
    -> <function _load_plugins_from_dirs at 0x7fceb0f59d90>
  File "/home/loke/.psources/flexget/lib/python3.7/site-packages/flexget/plugin.py", line 473, in _load_plugins_from_dirs
    _import_plugin(module_name, plugin_path)
    |              |            -> PosixPath('/home/loke/.psources/flexget/lib/python3.7/site-packages/flexget/plugins/clients/pyload.py')
    |              -> 'flexget.plugins.clients.pyload'
    -> <function _import_plugin at 0x7fceb0f59d08>
> File "/home/loke/.psources/flexget/lib/python3.7/site-packages/flexget/plugin.py", line 424, in _import_plugin
    import_module(module_name)
    |             -> 'flexget.plugins.clients.pyload'
    -> <function import_module at 0x7fceb2ba36a8>
  File "/home/loke/.psources/flexget/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           |          |           |    |        |        -> 0
           |          |           |    |        -> None
           |          |           |    -> 0
           |          |           -> 'flexget.plugins.clients.pyload'
           |          -> <function _gcd_import at 0x7fceb2ce5e18>
           -> <module 'importlib._bootstrap' (frozen)>
  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 "/home/loke/.psources/flexget/lib/python3.7/site-packages/flexget/plugins/clients/pyload.py", line 11, in <module>
    from packaging import version

ModuleNotFoundError: No module named 'packaging'
```

### Additional information:

- FlexGet version: 3.1.45 (3.1.44 works fine)
- Python version: 3.7
- Installation method: virtualenv
- Using daemon (yes/no): yes 
- OS and version: debian 10




Discussion:
Thank you for detailing which version works and which does not. This helps narrowing issue down a lot.
@paranoidi New pyload pr added packaging requirement, we either just need to add it to deps or make it optional in that plugin.
@gazpachoking how was this not caught by ci? It should be optional dep imo.

Resolving patch:
diff --git a/flexget/plugins/clients/pyload.py b/flexget/plugins/clients/pyload.py
--- a/flexget/plugins/clients/pyload.py
+++ b/flexget/plugins/clients/pyload.py
@@ -8,7 +8,6 @@
 from flexget.event import event
 from flexget.utils import json
 from flexget.utils.template import RenderError
-from packaging import version
 logger = logger.bind(name='pyload')
 
 
@@ -123,6 +122,15 @@ def on_task_output(self, task, config):
 
         self.add_entries(task, config)
 
+    @staticmethod
+    def get_version_from_packaging():
+        version = None
+        try:
+            from packaging import version
+        except ModuleNotFoundError:
+            logger.warning('packaging is not installed')
+        return version
+
     def add_entries(self, task, config):
         """Adds accepted entries"""
 
@@ -152,7 +160,8 @@ def add_entries(self, task, config):
         set_package_data_command = 'setPackageData'
 
         is_pyload_ng = False
-        if version.parse(remote_version) >= version.parse('0.5'):
+        version = self.get_version_from_packaging()
+        if version and version.parse(remote_version) >= version.parse('0.5'):
             parse_urls_command = 'parse_urls'
             add_package_command = 'add_package'
             set_package_data_command = 'set_package_date'


Test patch: