gorte
gorte

Reputation: 23

How can I run a python script using the IPython console in Spyder?

This command runs under bash on Linux:

python file.py variables

But when I write it to the IPython console in Spyder I get:

SyntaxError: invalid syntax

Q: How can I run a python script using the IPython console in Spyder?

Upvotes: 1

Views: 5917

Answers (2)

Carlos Cordoba
Carlos Cordoba

Reputation: 34186

(Spyder maintainer here) To run a Python file in Spyder, you just need to open it in its editor and the go to the menu

Run > Run file

or press F5. That basically reads the contents of the file and executes it with exec (as it was suggested in the answer by Jeremy Hue).

If you want to pass arguments to your script, please see my answer for that here.

Upvotes: 2

Jeremy H
Jeremy H

Reputation: 423

Your IPython console is already running Python, whereas the command python file.py in bash is basically saying 'run file.py using Python'.

Check out this solution if you want to run file.py explicitly via the IPython console run program in Python shell

Upvotes: 0

Related Questions