TUFLOW-Support / QGIS-TUFLOW-Plugin

TUFLOW related QGIS Plugins
9 stars 7 forks source link

[Linux - v3.11 and v3.11.0.1] ImportError: cannot import name 'DETACHED_PROCESS' from 'subprocess' #39

Closed ZedeN1 closed 3 weeks ago

ZedeN1 commented 2 months ago

Updating to the newest available plugin in the QGIS repository v3.11 / developer plugin v3.11.0.1 breaks the plugin on Linux.

Couldn't load plugin 'tuflow' due to an error when calling its classFactory() method 

ImportError: cannot import name 'DETACHED_PROCESS' from 'subprocess' (/usr/lib/python3.10/subprocess.py) 
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/qgis/utils.py", line 426, in _startPlugin
    plugins[packageName] = package.classFactory(iface)
  File "/home/rhianna/.local/share/QGIS/QGIS3/profiles/default/python/plugins/tuflow/__init__.py", line 78, in classFactory
    from .tuflowqgis_menu import tuflowqgis_menu
  File "/usr/lib/python3/dist-packages/qgis/utils.py", line 923, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/home/rhianna/.local/share/QGIS/QGIS3/profiles/default/python/plugins/tuflow/tuflowqgis_menu.py", line 44, in 
    from subprocess import Popen, PIPE, DETACHED_PROCESS
ImportError: cannot import name 'DETACHED_PROCESS' from 'subprocess' (/usr/lib/python3.10/subprocess.py)

Python version: 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] 
QGIS version: 3.36.2-Maidenhead Maidenhead, 6d250527200 

Python Path:
/usr/share/qgis/python
/home/rhianna/.local/share/QGIS/QGIS3/profiles/default/python
/home/rhianna/.local/share/QGIS/QGIS3/profiles/default/python/plugins
/usr/share/qgis/python/plugins
/usr/lib/python310.zip
/usr/lib/python3.10
/usr/lib/python3.10/lib-dynload
/usr/local/lib/python3.10/dist-packages
/usr/lib/python3/dist-packages
/home/rhianna/.local/share/QGIS/QGIS3/profiles/default/python
/home/rhianna/.local/share/QGIS/QGIS3/profiles/default/python/plugins/shapetools/ext-libs
uname -a
Linux inver 5.15.0-105-generic #115-Ubuntu SMP Mon Apr 15 09:52:04 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.4 LTS
Release:        22.04
Codename:       jammy
ZedeN1 commented 2 months ago

Below works, but not sure if it is appropriate.

Changing tuflowqgis_menu.py:

from subprocess import Popen, PIPE, DETACHED_PROCESS
import sys

to

import sys
if sys.platform != 'win32':
    from subprocess import Popen, PIPE
else:
    from subprocess import Popen, PIPE, DETACHED_PROCESS

and changing

       process = subprocess.Popen(command, creationflags=DETACHED_PROCESS, start_new_session=True)

to

        if sys.platform != 'win32':
            process = subprocess.Popen(command, cwd="/",
                 stdout=subprocess.PIPE,
                 stderr=subprocess.STDOUT,
                 start_new_session=True)
        else:
            process = subprocess.Popen(command, creationflags=DETACHED_PROCESS, start_new_session=True)
TUFLOW-Support commented 2 months ago

Hi,

Sorry about that

I have not tested the TUFLOW runner on Linux.

I had a guard to give an error if someone tried to run it on Linux: if os.name != 'nt':

However, the include issue occurs even before you get there (which I wasn't aware of).

I will make a change along the lines that you have so it doesn't prevent people from using the runner. For now will have to let people know that they can't use the runner on Linux for now if they try.

Rusty Jones Technical Lead

[cid:7b9d3573-9d0b-4e6b-a6e1-99d69696e8e0]https://www.tuflow.com/ TUFLOW Productshttps://www.tuflow.com/products/ | TUFLOW Pricinghttps://www.tuflow.com/pricing/ | TUFLOW Supporthttps://www.tuflow.com/support/ | TUFLOW Traininghttps://www.tuflow.com/training/ | LinkedInhttps://www.linkedin.com/groups/1908583/ | YouTubehttps://www.youtube.com/channel/UCZuGrIP8ayOwC1ojmnZrgPg

New TUFLOW Release 2023-03-AE now available: Release Noteshttps://docs.tuflow.com/classic-hpc/release/2023-03-AE/ | Downloads Pagehttps://scanmail.trustwave.com/?c=16827&d=nZvZ5BMwYX9Zmz8YsQf3aztB9zXBhmTTKV2c7BjquA&u=https%3a%2f%2fwww.tuflow.com%2fdownloads%2f%23tuflow


From: ZedeN1 @.> Sent: Tuesday, April 23, 2024 5:10 AM To: TUFLOW-Support/QGIS-TUFLOW-Plugin @.> Cc: Subscribed @.***> Subject: Re: [TUFLOW-Support/QGIS-TUFLOW-Plugin] [Linux - v3.11 and v3.11.0.1] ImportError: cannot import name 'DETACHED_PROCESS' from 'subprocess' (Issue #39)

Below works, but not sure if it is appropriate.

Changing ``

from subprocess import Popen, PIPE, DETACHED_PROCESS import sys

to

import sys if sys.platform != 'win32': from subprocess import Popen, PIPE else: from subprocess import Popen, PIPE, DETACHED_PROCESS

and changing

   process = subprocess.Popen(command, creationflags=DETACHED_PROCESS, start_new_session=True)

to

    if sys.platform != 'win32':
        process = subprocess.Popen(command, cwd="/",
             stdout=subprocess.PIPE,
             stderr=subprocess.STDOUT,
             start_new_session=True)
    else:
        process = subprocess.Popen(command, creationflags=DETACHED_PROCESS, start_new_session=True)

— Reply to this email directly, view it on GitHubhttps://github.com/TUFLOW-Support/QGIS-TUFLOW-Plugin/issues/39#issuecomment-2071923531, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABB5WFA6IUV6DBH66GPK23LY6YXQDAVCNFSM6AAAAABGUQWTS6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZRHEZDGNJTGE. You are receiving this because you are subscribed to this thread.Message ID: @.***>

ZedeN1 commented 3 weeks ago

v3.11.1 fixed the issue.