Repository: OpenNMT/OpenNMT-py

Issue:
Error when import SRU
Python 3.6.1 |Anaconda custom (64-bit)| (default, May 11 2017, 13:25:24) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import onmt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\python\OpenNMT-py-master\onmt\__init__.py", line 4, in <module>
    from onmt.Trainer import Trainer, Statistics
  File "D:\python\OpenNMT-py-master\onmt\Trainer.py", line 19, in <module>
    import onmt.modules
  File "D:\python\OpenNMT-py-master\onmt\modules\__init__.py", line 16, in <module>
    from onmt.modules.SRU import check_sru_requirement
  File "D:\python\OpenNMT-py-master\onmt\modules\SRU.py", line 349, in <module>
    if check_sru_requirement():
  File "D:\python\OpenNMT-py-master\onmt\modules\SRU.py", line 45, in check_sru_requirement
    stdin=pip_out.stdout)
  File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 336, in check_output
    **kwargs).stdout
  File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 403, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 990, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

I have already installed cupy and pynvrtc.
Error when import SRU
Python 3.6.1 |Anaconda custom (64-bit)| (default, May 11 2017, 13:25:24) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import onmt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\python\OpenNMT-py-master\onmt\__init__.py", line 4, in <module>
    from onmt.Trainer import Trainer, Statistics
  File "D:\python\OpenNMT-py-master\onmt\Trainer.py", line 19, in <module>
    import onmt.modules
  File "D:\python\OpenNMT-py-master\onmt\modules\__init__.py", line 16, in <module>
    from onmt.modules.SRU import check_sru_requirement
  File "D:\python\OpenNMT-py-master\onmt\modules\SRU.py", line 349, in <module>
    if check_sru_requirement():
  File "D:\python\OpenNMT-py-master\onmt\modules\SRU.py", line 45, in check_sru_requirement
    stdin=pip_out.stdout)
  File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 336, in check_output
    **kwargs).stdout
  File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 403, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 990, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

I have already installed cupy and pynvrtc.


Discussion:

Resolving patch:
diff --git a/onmt/modules/SRU.py b/onmt/modules/SRU.py
--- a/onmt/modules/SRU.py
+++ b/onmt/modules/SRU.py
@@ -6,6 +6,7 @@
 https://github.com/taolei87/sru/blob/master/cuda_functional.py.
 """
 import subprocess
+import platform
 import os
 import re
 import argparse
@@ -39,11 +40,14 @@ def check_sru_requirement(abort=False):
     """
     # Check 1.
     try:
-        pip_out = subprocess.Popen(
-            ('pip', 'freeze'), stdout=subprocess.PIPE)
-        subprocess.check_output(('grep', 'cupy\|pynvrtc'),
-                                stdin=pip_out.stdout)
-        pip_out.wait()
+        if platform.system() == 'Windows':
+            subprocess.check_output('pip freeze | findstr cupy', shell=True)
+            subprocess.check_output('pip freeze | findstr pynvrtc',
+                                    shell=True)
+        else:  # Unix-like systems
+            subprocess.check_output('pip freeze | grep -w cupy', shell=True)
+            subprocess.check_output('pip freeze | grep -w pynvrtc',
+                                    shell=True)
     except subprocess.CalledProcessError:
         if not abort:
             return False


Test patch: