0

There is this terminal command in which if I run someCommand my_file.txt, it works correctly..

When I tried to incorporate it into a python script as follows:

import os
os.system('someCommand /user_data/some_file.txt') 

I was prompted with the following error:

Traceback (most recent call last):
  File "/server/scripts/someCommand", line 6, in <module>
    import os
ImportError: No module named os

Tried using subprocess but same error persists. How can I rectify this and why is it that os module error occurs? In my python file, os is working for sure..

pvg
  • 2,673
  • 4
  • 17
  • 31
dissidia
  • 1,531
  • 3
  • 23
  • 53
  • Possible duplicate of http://stackoverflow.com/questions/28534506/python-importerror-no-module-named-os – Antimony May 16 '17 at 00:05
  • Possible duplicate of [Calling an external command in Python](http://stackoverflow.com/questions/89228/calling-an-external-command-in-python) – Torxed May 16 '17 at 00:14
  • @Antimony - user doesn't set `PYTHONHOME` - how is that a duplicate? – tdelaney May 16 '17 at 00:18
  • @Torxed - I don't see how that solves the problem. `os` should be there. – tdelaney May 16 '17 at 00:19
  • @tdelaney But perhaps they did that a while back and forgot about it? I added that link as a suggestion that they try whatever has been proposed there. – Antimony May 16 '17 at 00:22
  • What is in the `someCommand` script (that's the one producing the error). – Paul Rooney May 16 '17 at 00:22
  • @PaulRooney that `someCommand` was a terminal command written and put there in place by someone in my company (quite) some time ago. I was trying to use the iteration in my python script and combine it with this `someCommand` – dissidia May 16 '17 at 00:24
  • @Antimony - it would certainly be worth finding out if the example is the whole script. dissidia - is this exactly the script you ran? – tdelaney May 16 '17 at 00:31
  • ...and did you run this script from the command line like the example that worked? – tdelaney May 16 '17 at 00:34
  • @tdelaney Yes, when running `someCommand my_file.txt` purely in the terminal, it works. The import error occurs only happens when I inserted this command into my python script – dissidia May 16 '17 at 00:35
  • But is the 2 line example you posted your script? This should work and we are trying to figure out where things went wrong. Things like setting `PYTHONPATH` and `PYTHONHOME` or even running from a python virtual env can be problematic. – tdelaney May 16 '17 at 00:37
  • Maybe it got to do with my python, I will try to check with someone in my company.. Even so, getting an importError about the os is weird... – dissidia May 16 '17 at 00:58

0 Answers0