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.

8
  • 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. Commented Jul 5, 2016 at 15:18
  • Sure. Just a moment. Commented Jul 5, 2016 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)? Commented Jul 5, 2016 at 15:27
  • Both A and B have the same absolute file path. Commented Jul 5, 2016 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. Commented Jul 5, 2016 at 15:42

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.