Luca
Luca

Reputation: 595

Python: Can't Find Module When Running Script Within a Script

I created a Python program A for which I later wrote another Python program B that called A using the subprocess library. I had a module foo installed in A which worked perfectly fine until I started calling the program from B. Now, I get the error:

ImportError: no module named foo

when B is called. I am sure that the module is installed correctly, because when I enter a python shell from the same directory as A and B, I am able to import foo and use its functions successfully. So, why wouldn't foo import correctly in this situation?

EDIT

I call program B from program A using the following call.

call(["python", "levMap9.py", inputFilePath, outputFilePath, scalingFactor])

In program B (levMap9.py), I make the following import, which gives the import error for some reason

import Levenshtein as LV

EDIT2

I realize that it is probably worth mentioning that these programs worked fine when I initially developed them on OSX, but now are having this problem on a Windows 8 machine.

Upvotes: 2

Views: 2675

Answers (1)

Luca
Luca

Reputation: 595

I tried adding the path to the Levenshtein module in PYTHONPATH (it already existed in PATH), and that solved my problem; though I don't entirely understand why. Thanks to those who contributed advice.

EDIT

Found the real answer to my problem here: How to execute Python scripts in Windows?

Upvotes: 1

Related Questions