2

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.

Luca
  • 515
  • 5
  • 17
  • Could you eventually provide some minimal working three python file code, so one can directly spot the culprit (it soon starts to bend my old brain, when I have to follow such a setting in prose ;-) Thanks. – Dilettant Jul 05 '16 at 15:18
  • Sure. Just a moment. – Luca Jul 05 '16 at 15:19
  • And when one outputs `levMap9.py` perspective on `sys.path` in that call situation (via print or raise or in an `except ImportError ...` clause of a try block around the `Levenshtein` import effort ... would it contain the folder needed? Are the "places" of the two files relevant (compared to the place ot the imported modules implementation)? – Dilettant Jul 05 '16 at 15:27
  • Both A and B have the same absolute file path. – Luca Jul 05 '16 at 15:36
  • ... then they would be identical ;-) but got it: Same folder. Ok. Sometimes it is better to show a more wide area of your problem to get answers: So albeit these scripts are both coded in python, you have to call them "like alien binaries" and A calling B worked, but B calling A does not? The working case, could it be shown in the question? I ask myself in these situations of refactoring: What did I change, to make it break? But then I look at my screen or git move backward and forward in time ... so please try to check that. – Dilettant Jul 05 '16 at 15:42
  • I think I've got the problem figured out, but thank you for your help. – Luca Jul 05 '16 at 15:46
  • You may want to construct and show us a [mcve]. – boardrider Jul 06 '16 at 12:03
  • Well, this question is resolved. But I will keep that in mind for future reference. – Luca Jul 06 '16 at 12:15

1 Answers1

1

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?

Community
  • 1
  • 1
Luca
  • 515
  • 5
  • 17