0

I'm trying to us a multiprocessing script to run two python scripts at the same time. The problem I'm having is that when I run the script I end up with an import error for a number of modules in the other two scripts. I've tried various other ways of running these two scripts and this seems to be the best way.

This is for a degree project which involves natural language processing, text to speech and speech to text, so the modules I'm using are nltk, google.cloud.speech, playsound and a few others. Here is my code:

import os
from multiprocessing import Process

def intent():
    os.system('IntentDetection.py')     
def speak():
    os.system('TextToSpeech.py') 

if __name__ == '__main__':
    p = Process(target=intent())
    q = Process(target=speak())
    p.start()
    q.start()

I'm expecting for it to run both scripts so that I can talk to the system, it interprets the text and then speaks back. All the scripts are working on their own I just can't get them to run together. This is the error I get:

Traceback (most recent call last):
  File "IntentDetection.py", line 2, in <module>
    import nltk
ImportError: No module named nltk
Traceback (most recent call last):
  File "TextToSpeech.py", line 2, in <module>
    from playsound import playsound
ImportError: No module named playsound

Any help would be greatly appreciated.

  • Are you running in a virtual environment? If things work inside of it, but not via `os.system`, it might well be due to `os.system` escaping the virtualenv. See: https://stackoverflow.com/q/1691076/1067211 – Avery Apr 03 '19 at 15:56
  • No not running inside a virtual environment, I know I probably should be though. This is my first Python project. – Josh Ball Apr 03 '19 at 18:40
  • I think you are right with the problem being with os.system though. Could it be calling the wrong python, ie 2.7? Also read somewhere I should be using subprocess.call insead of os.system? – Josh Ball Apr 03 '19 at 18:53
  • @JoshBall: Run [this replace key = 'nltk'](https://stackoverflow.com/a/55407517/7414759), [edit] your Question and show the output. – stovfl Apr 03 '19 at 19:59

0 Answers0