👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
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 than 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?
👻 Read also: what is the best laptop for engineering students?
We hope this article has helped you to resolve the problem. Apart from Running Bash commands in Python, check other ast Python module-related topics.
Want to excel in Python? See our review of the best Python online courses 2023. If you are interested in Data Science, check also how to learn programming in R.
By the way, this material is also available in other languages:
- Italiano Running Bash commands in Python
- Deutsch Running Bash commands in Python
- Français Running Bash commands in Python
- Español Running Bash commands in Python
- Türk Running Bash commands in Python
- Русский Running Bash commands in Python
- Português Running Bash commands in Python
- Polski Running Bash commands in Python
- Nederlandse Running Bash commands in Python
- 中文 Running Bash commands in Python
- 한국어 Running Bash commands in Python
- 日本語 Running Bash commands in Python
- हिन्दी Running Bash commands in Python
Massachussetts | 2023-04-01
Thanks for explaining! I was stuck with Running Bash commands in Python for some hours, finally got it done 🤗. Will get back tomorrow with feedback
London | 2023-04-01
Thanks for explaining! I was stuck with Running Bash commands in Python for some hours, finally got it done 🤗. Checked yesterday, it works!
Paris | 2023-04-01
os Python module is always a bit confusing 😭 Running Bash commands in Python is not the only problem I encountered. I just hope that will not emerge anymore