Reputation: 15008
I am having a weird problem.
I am on Py2.7 and I am calling a py file from python script. Below is my code
caller.py
import os
import subprocess
filename = 'file.py'
data = 'aXD'
output = subprocess.check_output(['python', filename,data], shell=False)
file.py
import sys
import os
import xmltodict
args = sys.argv
xml = args[1].strip('\n')
xml = xml.strip()
pid = str(os.getpid())
result = {'msg':'ok',"pid":pid}
print(result)
And it gives error:
import xmltodict
ImportError: No module named xmltodict
Traceback (most recent call last):
The module is RIGHT there since the file runs perfect when executing individually.
Upvotes: 3
Views: 53567
Reputation: 57
In my case started throwing error:"Fatal error in launcher:The system cannot find the file specified." In that case find the python.exe location using then execute <path\to\python.ex -m pip install xmltodict>
Upvotes: 0
Reputation: 1
Install this package for xmltodict with conda, you need to run one of the following:
conda install -c conda-forge xmltodict
conda install -c conda-forge/label/gcc7 xmltodict
conda install -c conda-forge/label/cf201901 xmltodict
once the package xmltodict is installed, re-run the script. It will work.
Upvotes: 0
Reputation: 159
The issue can be resolved trough this simple way:
use 'pip' - python package manager
$ sudo pip install xmltodict
This should install missing module and you shouldn't have problems with this module.
Upvotes: 11
Reputation: 48028
As an answer, instead of in comments -> the issue is that you've got more than one python interpreter installed and you're getting a different one than you expected when you launched it via subprocess.check_output
. You should address that by changing your invocation like so:
output = subprocess.check_output([sys.executable, filename,data], shell=False)
Which will ensure, at the very least, that both scripts are run by the same interpreter.
Upvotes: 2
Reputation: 15170
Add "current directory" to your Python path so it will find modules in the directory alongside the main program
import sys
sys.path.append('.')
Upvotes: 1