On my local machine I run a python script which contains this line
bashCommand = "cwm --rdf test.rdf --ntriples > test.nt"
os.system(bashCommand)
This works fine.
Then I run the same code on a server and I get the following error message
'import site' failed; use -v for traceback
Traceback (most recent call last):
File "/usr/bin/cwm", line 48, in <module>
from swap import diag
ImportError: No module named swap
So what I did then is I inserted a "print bashCommand" which prints me then the command in the terminal before it runs it with os.system().
Of course I get again the error (caused by os.system(bashCommand)) but before that error it prints the command in the terminal. Then I just copied that output and did a copy paste into the terminal and hit enter and it works...
Does anyone have a clue what's going on :(?
According to the error you are missing a package named swap on the server. This
/usr/bin/cwm
requires it. If you're on Ubuntu/Debian, installpython-swap
using aptitude.The pythonic way of doing this is using
subprocess.Popen
subprocess.Popen
takes a list where the first element is the command to be run followed by any command line arguments.As an example:
Also you can use 'os.popen'. Example:
Output: