nodejs child_process package fails to work for python script only when using certain imports












0














I am writing a simple Electron app on Windows that uses several python files utilizing various python machine learning libraries. My goal at this point is to simply click a button which executes a python script that either stores output to a file local to the directory of the python script or returns output to the Electron app--either way is fine.



Using a few different methods (exec, spawn, etc). I have had success calling the python script, and have had the python script correctly write test values to files and correctly return test values to my applications.



const { spawn } = require('child_process');

const pyProg = spawn('python', ['./../path/to/pyfile/cmd_test.py', 'arg1', 'arg2'...], {detached: true});

pyProg.stdout.on('data', function(data) {
alert(data);
console.log(data.toString());
});


The issue is, once I import either of two necessary libraries for my python script (pandas and sklearn), the script halts and neither writes to file nor returns output. This is not the case when importing certain other libraries like numpy or sys. If I comment out the pandas (or sklearn) import, everything works fine.



import sys
import ast
import numpy as np
#import pandas as pd


Whats more, if I manually call the same command line command that the Electron app executes from the same directory as the Electron app itself, the program runs correctly, and the both the file writing and output work correctly, regardless of whether or not I import pandas or sklearn.



python ./../path/to/pyfile/cmd_test.py arg1 arg2









share|improve this question



























    0














    I am writing a simple Electron app on Windows that uses several python files utilizing various python machine learning libraries. My goal at this point is to simply click a button which executes a python script that either stores output to a file local to the directory of the python script or returns output to the Electron app--either way is fine.



    Using a few different methods (exec, spawn, etc). I have had success calling the python script, and have had the python script correctly write test values to files and correctly return test values to my applications.



    const { spawn } = require('child_process');

    const pyProg = spawn('python', ['./../path/to/pyfile/cmd_test.py', 'arg1', 'arg2'...], {detached: true});

    pyProg.stdout.on('data', function(data) {
    alert(data);
    console.log(data.toString());
    });


    The issue is, once I import either of two necessary libraries for my python script (pandas and sklearn), the script halts and neither writes to file nor returns output. This is not the case when importing certain other libraries like numpy or sys. If I comment out the pandas (or sklearn) import, everything works fine.



    import sys
    import ast
    import numpy as np
    #import pandas as pd


    Whats more, if I manually call the same command line command that the Electron app executes from the same directory as the Electron app itself, the program runs correctly, and the both the file writing and output work correctly, regardless of whether or not I import pandas or sklearn.



    python ./../path/to/pyfile/cmd_test.py arg1 arg2









    share|improve this question

























      0












      0








      0







      I am writing a simple Electron app on Windows that uses several python files utilizing various python machine learning libraries. My goal at this point is to simply click a button which executes a python script that either stores output to a file local to the directory of the python script or returns output to the Electron app--either way is fine.



      Using a few different methods (exec, spawn, etc). I have had success calling the python script, and have had the python script correctly write test values to files and correctly return test values to my applications.



      const { spawn } = require('child_process');

      const pyProg = spawn('python', ['./../path/to/pyfile/cmd_test.py', 'arg1', 'arg2'...], {detached: true});

      pyProg.stdout.on('data', function(data) {
      alert(data);
      console.log(data.toString());
      });


      The issue is, once I import either of two necessary libraries for my python script (pandas and sklearn), the script halts and neither writes to file nor returns output. This is not the case when importing certain other libraries like numpy or sys. If I comment out the pandas (or sklearn) import, everything works fine.



      import sys
      import ast
      import numpy as np
      #import pandas as pd


      Whats more, if I manually call the same command line command that the Electron app executes from the same directory as the Electron app itself, the program runs correctly, and the both the file writing and output work correctly, regardless of whether or not I import pandas or sklearn.



      python ./../path/to/pyfile/cmd_test.py arg1 arg2









      share|improve this question













      I am writing a simple Electron app on Windows that uses several python files utilizing various python machine learning libraries. My goal at this point is to simply click a button which executes a python script that either stores output to a file local to the directory of the python script or returns output to the Electron app--either way is fine.



      Using a few different methods (exec, spawn, etc). I have had success calling the python script, and have had the python script correctly write test values to files and correctly return test values to my applications.



      const { spawn } = require('child_process');

      const pyProg = spawn('python', ['./../path/to/pyfile/cmd_test.py', 'arg1', 'arg2'...], {detached: true});

      pyProg.stdout.on('data', function(data) {
      alert(data);
      console.log(data.toString());
      });


      The issue is, once I import either of two necessary libraries for my python script (pandas and sklearn), the script halts and neither writes to file nor returns output. This is not the case when importing certain other libraries like numpy or sys. If I comment out the pandas (or sklearn) import, everything works fine.



      import sys
      import ast
      import numpy as np
      #import pandas as pd


      Whats more, if I manually call the same command line command that the Electron app executes from the same directory as the Electron app itself, the program runs correctly, and the both the file writing and output work correctly, regardless of whether or not I import pandas or sklearn.



      python ./../path/to/pyfile/cmd_test.py arg1 arg2






      javascript python node.js pandas electron






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 '18 at 15:55









      user10686544

      1




      1
























          1 Answer
          1






          active

          oldest

          votes


















          0














          It sounds like python is not finding the installed packages.



          The difference between sys, ast and numpy with pandas is that the first 3 are standard libraries and pandas is a third party. If you installed it via pip try adding the installed libraries path to your python path. Put this on top of the python





          • If you are using python 3:



            import sys
            sys.path.append(C:Users%USERNAME%AppDataRoamingPythonPython3X[-32]site-packages)



          Notice how there is an X and a -32 between brackets. The X should be your python 3 sub-version and you should put the -32 if you installed the 32 bit version of python.





          • If you are using 2.7:



            import sys
            sys.path.append(c:Python27Libsite-packages)



          This are the default routes for windows they could be different in your computer if you set that in the installation





          • If you are on a unix-like system then add this:



            import sys
            sys.path.append(/usr/lib/pythonX.Y/site-packages)



          Notice the X and Y this should be the version and sub-version respectively. If you don't know your python version just execute in the console/terminal:



          python --version


          It should return something like this:



          Python 3.7.1


          Use only the first 2 numbers for the path.






          share|improve this answer





















          • Thanks for your answer. I am using anaconda, and I have pandas in 'C:\Users*\Anaconda3\lib\site-packages'. I verified that this directory is on my sys.path for my interpreter. Do you have any other thoughts or suggestions?
            – user10686544
            Nov 21 '18 at 17:19










          • For what I had read the interpreter automatically adds those paths, but the python executable doesn't. So it should work if is the file that adds it.
            – martor
            Nov 21 '18 at 17:32










          • Here is another example of this problem.
            – martor
            Nov 21 '18 at 18:01












          • Even using the sys.path.append explicitly to the file to run does not work. There is definitely some path issue here, but it is difficult to say what it is.
            – user10686544
            Nov 21 '18 at 18:57










          • did you try adding just the site-packages or directly to pandas?
            – martor
            Nov 21 '18 at 19:05











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415875%2fnodejs-child-process-package-fails-to-work-for-python-script-only-when-using-cer%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          It sounds like python is not finding the installed packages.



          The difference between sys, ast and numpy with pandas is that the first 3 are standard libraries and pandas is a third party. If you installed it via pip try adding the installed libraries path to your python path. Put this on top of the python





          • If you are using python 3:



            import sys
            sys.path.append(C:Users%USERNAME%AppDataRoamingPythonPython3X[-32]site-packages)



          Notice how there is an X and a -32 between brackets. The X should be your python 3 sub-version and you should put the -32 if you installed the 32 bit version of python.





          • If you are using 2.7:



            import sys
            sys.path.append(c:Python27Libsite-packages)



          This are the default routes for windows they could be different in your computer if you set that in the installation





          • If you are on a unix-like system then add this:



            import sys
            sys.path.append(/usr/lib/pythonX.Y/site-packages)



          Notice the X and Y this should be the version and sub-version respectively. If you don't know your python version just execute in the console/terminal:



          python --version


          It should return something like this:



          Python 3.7.1


          Use only the first 2 numbers for the path.






          share|improve this answer





















          • Thanks for your answer. I am using anaconda, and I have pandas in 'C:\Users*\Anaconda3\lib\site-packages'. I verified that this directory is on my sys.path for my interpreter. Do you have any other thoughts or suggestions?
            – user10686544
            Nov 21 '18 at 17:19










          • For what I had read the interpreter automatically adds those paths, but the python executable doesn't. So it should work if is the file that adds it.
            – martor
            Nov 21 '18 at 17:32










          • Here is another example of this problem.
            – martor
            Nov 21 '18 at 18:01












          • Even using the sys.path.append explicitly to the file to run does not work. There is definitely some path issue here, but it is difficult to say what it is.
            – user10686544
            Nov 21 '18 at 18:57










          • did you try adding just the site-packages or directly to pandas?
            – martor
            Nov 21 '18 at 19:05
















          0














          It sounds like python is not finding the installed packages.



          The difference between sys, ast and numpy with pandas is that the first 3 are standard libraries and pandas is a third party. If you installed it via pip try adding the installed libraries path to your python path. Put this on top of the python





          • If you are using python 3:



            import sys
            sys.path.append(C:Users%USERNAME%AppDataRoamingPythonPython3X[-32]site-packages)



          Notice how there is an X and a -32 between brackets. The X should be your python 3 sub-version and you should put the -32 if you installed the 32 bit version of python.





          • If you are using 2.7:



            import sys
            sys.path.append(c:Python27Libsite-packages)



          This are the default routes for windows they could be different in your computer if you set that in the installation





          • If you are on a unix-like system then add this:



            import sys
            sys.path.append(/usr/lib/pythonX.Y/site-packages)



          Notice the X and Y this should be the version and sub-version respectively. If you don't know your python version just execute in the console/terminal:



          python --version


          It should return something like this:



          Python 3.7.1


          Use only the first 2 numbers for the path.






          share|improve this answer





















          • Thanks for your answer. I am using anaconda, and I have pandas in 'C:\Users*\Anaconda3\lib\site-packages'. I verified that this directory is on my sys.path for my interpreter. Do you have any other thoughts or suggestions?
            – user10686544
            Nov 21 '18 at 17:19










          • For what I had read the interpreter automatically adds those paths, but the python executable doesn't. So it should work if is the file that adds it.
            – martor
            Nov 21 '18 at 17:32










          • Here is another example of this problem.
            – martor
            Nov 21 '18 at 18:01












          • Even using the sys.path.append explicitly to the file to run does not work. There is definitely some path issue here, but it is difficult to say what it is.
            – user10686544
            Nov 21 '18 at 18:57










          • did you try adding just the site-packages or directly to pandas?
            – martor
            Nov 21 '18 at 19:05














          0












          0








          0






          It sounds like python is not finding the installed packages.



          The difference between sys, ast and numpy with pandas is that the first 3 are standard libraries and pandas is a third party. If you installed it via pip try adding the installed libraries path to your python path. Put this on top of the python





          • If you are using python 3:



            import sys
            sys.path.append(C:Users%USERNAME%AppDataRoamingPythonPython3X[-32]site-packages)



          Notice how there is an X and a -32 between brackets. The X should be your python 3 sub-version and you should put the -32 if you installed the 32 bit version of python.





          • If you are using 2.7:



            import sys
            sys.path.append(c:Python27Libsite-packages)



          This are the default routes for windows they could be different in your computer if you set that in the installation





          • If you are on a unix-like system then add this:



            import sys
            sys.path.append(/usr/lib/pythonX.Y/site-packages)



          Notice the X and Y this should be the version and sub-version respectively. If you don't know your python version just execute in the console/terminal:



          python --version


          It should return something like this:



          Python 3.7.1


          Use only the first 2 numbers for the path.






          share|improve this answer












          It sounds like python is not finding the installed packages.



          The difference between sys, ast and numpy with pandas is that the first 3 are standard libraries and pandas is a third party. If you installed it via pip try adding the installed libraries path to your python path. Put this on top of the python





          • If you are using python 3:



            import sys
            sys.path.append(C:Users%USERNAME%AppDataRoamingPythonPython3X[-32]site-packages)



          Notice how there is an X and a -32 between brackets. The X should be your python 3 sub-version and you should put the -32 if you installed the 32 bit version of python.





          • If you are using 2.7:



            import sys
            sys.path.append(c:Python27Libsite-packages)



          This are the default routes for windows they could be different in your computer if you set that in the installation





          • If you are on a unix-like system then add this:



            import sys
            sys.path.append(/usr/lib/pythonX.Y/site-packages)



          Notice the X and Y this should be the version and sub-version respectively. If you don't know your python version just execute in the console/terminal:



          python --version


          It should return something like this:



          Python 3.7.1


          Use only the first 2 numbers for the path.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 '18 at 16:42









          martor

          56




          56












          • Thanks for your answer. I am using anaconda, and I have pandas in 'C:\Users*\Anaconda3\lib\site-packages'. I verified that this directory is on my sys.path for my interpreter. Do you have any other thoughts or suggestions?
            – user10686544
            Nov 21 '18 at 17:19










          • For what I had read the interpreter automatically adds those paths, but the python executable doesn't. So it should work if is the file that adds it.
            – martor
            Nov 21 '18 at 17:32










          • Here is another example of this problem.
            – martor
            Nov 21 '18 at 18:01












          • Even using the sys.path.append explicitly to the file to run does not work. There is definitely some path issue here, but it is difficult to say what it is.
            – user10686544
            Nov 21 '18 at 18:57










          • did you try adding just the site-packages or directly to pandas?
            – martor
            Nov 21 '18 at 19:05


















          • Thanks for your answer. I am using anaconda, and I have pandas in 'C:\Users*\Anaconda3\lib\site-packages'. I verified that this directory is on my sys.path for my interpreter. Do you have any other thoughts or suggestions?
            – user10686544
            Nov 21 '18 at 17:19










          • For what I had read the interpreter automatically adds those paths, but the python executable doesn't. So it should work if is the file that adds it.
            – martor
            Nov 21 '18 at 17:32










          • Here is another example of this problem.
            – martor
            Nov 21 '18 at 18:01












          • Even using the sys.path.append explicitly to the file to run does not work. There is definitely some path issue here, but it is difficult to say what it is.
            – user10686544
            Nov 21 '18 at 18:57










          • did you try adding just the site-packages or directly to pandas?
            – martor
            Nov 21 '18 at 19:05
















          Thanks for your answer. I am using anaconda, and I have pandas in 'C:\Users*\Anaconda3\lib\site-packages'. I verified that this directory is on my sys.path for my interpreter. Do you have any other thoughts or suggestions?
          – user10686544
          Nov 21 '18 at 17:19




          Thanks for your answer. I am using anaconda, and I have pandas in 'C:\Users*\Anaconda3\lib\site-packages'. I verified that this directory is on my sys.path for my interpreter. Do you have any other thoughts or suggestions?
          – user10686544
          Nov 21 '18 at 17:19












          For what I had read the interpreter automatically adds those paths, but the python executable doesn't. So it should work if is the file that adds it.
          – martor
          Nov 21 '18 at 17:32




          For what I had read the interpreter automatically adds those paths, but the python executable doesn't. So it should work if is the file that adds it.
          – martor
          Nov 21 '18 at 17:32












          Here is another example of this problem.
          – martor
          Nov 21 '18 at 18:01






          Here is another example of this problem.
          – martor
          Nov 21 '18 at 18:01














          Even using the sys.path.append explicitly to the file to run does not work. There is definitely some path issue here, but it is difficult to say what it is.
          – user10686544
          Nov 21 '18 at 18:57




          Even using the sys.path.append explicitly to the file to run does not work. There is definitely some path issue here, but it is difficult to say what it is.
          – user10686544
          Nov 21 '18 at 18:57












          did you try adding just the site-packages or directly to pandas?
          – martor
          Nov 21 '18 at 19:05




          did you try adding just the site-packages or directly to pandas?
          – martor
          Nov 21 '18 at 19:05


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415875%2fnodejs-child-process-package-fails-to-work-for-python-script-only-when-using-cer%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'