1

From in the notebook, it's easy to run an external python module with %run. For example, if I wanted to run foo.py:

 %run foo

But how does one run a file not ending in .py? For example, if I had a bash script, bar. When I try:

 %run bar
 ERROR: File `u'$bar.py'` not found.

A while back, someone showed me how to pass the filename so that %run doesn't append the .py suffix, but I can't dig it up!

Thanks

Some Context for why I want to do it this way

Thanks for the comments. To address why I'd like to do something like this, we are distributing an assignment in the IPython notebook for students in an intro programming class, and want them to use nbconvert to submit it as an HTML file. Many of them use windows, and are using Canopy as their Python distribution. To "open a terminal, cd to the working directory and running nbconvert" would be difficult, especially if nbconvert is not in their environmental variables. It would be much easier on us to just have a one-liner that they can run from within the notebook environment.

asked Feb 11, 2015 at 18:37
3
  • why would you want to do this? ... I dont have an answer to your question, but I have a hard time imagining a scenario where this is the right thing to do ... Commented Feb 11, 2015 at 18:38
  • possible duplicate of execute Bash command from IPython Commented Feb 11, 2015 at 18:43
  • Joran, I edited my answer to explain why we think it's a good approach. Commented Feb 11, 2015 at 18:55

2 Answers 2

1

Creator of ipython suggests this:

%%bash 
. ~/.bashrc
answered Feb 11, 2015 at 18:42
Sign up to request clarification or add additional context in comments.

Comments

0

Yes, the %%bash magic worked fine. Sorry I didn't catch this.

%%bash 
ipython nbconvert --to html worldmap_notebook.ipynb
answered Feb 11, 2015 at 18:49

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.