I'm having some very mysterious behavior with a script that fails to run. Obviously the script below is trivial and does nothing, but it's reproducing behavior in a real script. Here's the code inside a file called test.py
.
import os
os.chdir('/home/jacob/twcSite')
import app
app
is located in 'home/jacob/twcSite'
, which is a different directory than the current one, containing test.py
. If I type python test.py
at the command line, I get ImportError: No module named app
. However, if I simply type python
to launch the interactive interpreter and copy-paste the exact same three commands, then it works just fine without an import error.
What could possibly be causing this error? It's the same version of python. The exact same lines of code. Why do I get different behavior in either case? Just to give more details, if you print the output to os.getcwd()
before and after calling os.chdir
it does indeed claim to have changed to the right directory (though clearly that's not the case). I'm running Ubuntu 14.04, Python version 2.7.6.