Reputation: 2259
I've two Python scripts as given below
inner.py
#!/usr/bin/python
import os
import datetime
# <---- Some Code--->
main.py
#!/usr/bin/python
import os
import datetime
# <---- Some Code--->
subprocess.call(["/usr/bin/python",inner.py])
The problem is when the inner.py
script is called from the main.py
script it doesn't import any modules. For example it says
ImportError: No module named os
But when the script is executed standalone it works fine. Please help
Upvotes: 1
Views: 985
Reputation: 544
The following works perfectly fine for me, and it's modified because some of your code seemed a little incomplete.
inner.py
#!/usr/bin/python
import os
import datetime
print os.getcwd()
main.py
#!/usr/bin/python
import os
import datetime
import subprocess
import sys
# <---- Some Code--->
subprocess.call([sys.executable, "inner.py"])
Upvotes: 1