3

I am working on some projects these days. I have created 3 executable python files in my project called,

  1. crawler.py
  2. process_data.py
  3. process_csv.py

Then I have created run.py to execute the above three, one after one.


Problem -: when I tried to execute the process_csv.py file using run.py, it showed me

Traceback (most recent call last):
  File "processors/process_csv.py", line 1, in <module>
    import pandas as pd
ModuleNotFoundError: No module named 'pandas'

Interesting point -: But, if I tried to execute process_csv.py separately without using run.py, it was run without any pandas error.


process_csv.py

import pandas as pd

# my code

run.py

import subprocess

subprocess.run(['python', 'processors/process_data.py']) # this line is working fine
subprocess.run(['python ', 'processors/process_csv.py']) # error occur in this line
Kalana
  • 5,631
  • 7
  • 30
  • 51
  • Refer to this : https://stackoverflow.com/questions/46561725/python-subprocess-i-can-not-import-other-modules. I hope this helps – A DUBEY Dec 11 '20 at 05:19

1 Answers1

2

When I hardly navigate through Stackoverflow, I found a question that has some kind of relation to my question. I realized accepted answer of that question; can be applied to my question also. Then I have applied some changes to my script.

run.py

import subprocess
import sys

subprocess.run(['python', 'processors/process_data.py']) 
subprocess.Popen([sys.executable, "processors/process_csv.py"]).communicate()

This solution 100% worked for my script.

Kalana
  • 5,631
  • 7
  • 30
  • 51