Some simple options: Open a terminal in Jupyter, run your Python scripts in the terminal like you would in your local terminal. Make a notebook, and use %run as an entry in a cell. See here. This is more full featured then using !python in a cell . Answer from fomightez on discourse.jupyter.org
🌐
PyPI
pypi.org › project › runfile
runfile · PyPI
August 28, 2021 - # Hello world with two languages A Runfile that says hello using two languages! ## write_message Writes a message to the Runfile cache using shell. ```sh run_set "message" "Hello world!" ``` ## print_message Prints a stored message from the Runfile cache using Python.
      » pip install runfile
    
Published   Aug 28, 2021
Version   1.0.7
Discussions

Why does 'runfile' work in Spyder but not in Powershell?
hmmm... if i were to hazard a guess it would be because the whole Anaconda's package is pretty self contained. There are quite a few things that you would find works in Spyder that doesn't work in the command line. They run on different interpreters? Your machine might not be able to interpret the Python version that your script in written in? More on reddit.com
🌐 r/learnpython
1
4
September 13, 2015
How to work with pure python file (.py)
Hi, I have a python project built on pycharm, which has a bunch of .py files. I would like to work on the same files from jupyter environment. Is there any best practice for doing the same? I dont want to create notebooks (.pynb) files and execute the code as cells. More on discourse.jupyter.org
🌐 discourse.jupyter.org
7
0
May 18, 2020
hide the 'runfile (...)' expression when running a python script from Spyder
Is there a way to hide the 'runfile (...)' expression when running a python script from Spyder? Because it clutters the console. Especially for programs with short outputs where I might wan... More on github.com
🌐 github.com
4
November 30, 2017
Run a Python file in Command Prompt
How to run a Python file in Windows Command Prompt using the imput command? More on discuss.python.org
🌐 discuss.python.org
4
0
December 21, 2023
🌐
GitHub
github.com › spyder-ide › spyder › issues › 2254
How do I disable the 'runfile (...)' expression when running a python script from Spyder? · Issue #2254 · spyder-ide/spyder
March 16, 2015 - Whenever I run a python script from Spyder (v2.2.5), I see the 'runfile(...)' expression. How can I suppress this? I am using Spyder 2.2.5 on Ubuntu 14.04.2 LTS
Author   s0r2637
🌐
Reddit
reddit.com › r/learnpython › why does 'runfile' work in spyder but not in powershell?
r/learnpython on Reddit: Why does 'runfile' work in Spyder but not in Powershell?
September 13, 2015 -

I have Anaconda3 installed with python 3.4, on Windows 8. In the interest of really trying to understand what's going on, I'm practicing all the different ways to run a script - using the 'Run file' button in Spyder, using the console in Spyder, command line within Powershell, and command line after starting python in Powershell.

I was curious as to why the 'runfile' command works in the Spyder console but not in python within Powershell. That is, I can put this in in the Spyder console:

 In [1]: runfile('endome\pythonscript.py')

but, when I try to do the same thing after launching python in Powershell, runfile isn't recognized:

>>> runfile('endome\pythonscript.py')
 Traceback (most recent call last):
      File "(stdin)", line 1, in (module)
NameError: name 'runfile' is not defined

Now, I did learn how to run a script in Powershell using:

>>> exec(open('endome\pythonscript.py').read())

But, I'm just curious why runfile works in Spyder but not in Powershell (or cmd for that matter).

🌐
Real Python
realpython.com › run-python-scripts
How to Run Your Python Scripts and Code – Real Python
February 25, 2026 - Running Python scripts is essential for executing your code. You can run Python scripts from the command line using python script.py, directly by making files executable with shebangs on Unix systems, or through IDEs and code editors.
Find elsewhere
🌐
Python
docs.python.org › 3 › library › os.html
os — Miscellaneous operating system interfaces
February 23, 2026 - Source code: Lib/os.py This module provides a portable way of using operating system dependent functionality. If you just want to read or write a file see open(), if you want to manipulate paths, s...
🌐
Astral
docs.astral.sh › uv › guides › scripts
Running scripts | uv
December 9, 2025 - A Python script is a file intended for standalone execution, e.g., with python <script>.py.
🌐
Jupyter Community Forum
discourse.jupyter.org › jupyterlab
How to work with pure python file (.py) - JupyterLab - Jupyter Community Forum
May 18, 2020 - Hi, I have a python project built on pycharm, which has a bunch of .py files. I would like to work on the same files from jupyter environment. Is there any best practice for doing the same? I dont want to create notebooks (.pynb) files and execute the code as cells.
🌐
Google Groups
groups.google.com › g › spyderlib › c › q4Ex0CZPycU
Re: [spyder] How to run my script file....
If you open this file in Spyder, you can execute it by hitting F5. You can run it interactively like MATLAB by first hitting F6, select "Execute in current Python or IPython interpreter", and then hit Run.
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 115000781890-Quick-command-to-run-file-in-console-in-Pycharm-using-the-command-runfile
Quick command to run file in console in Pycharm using the command runfile(). – IDEs Support (IntelliJ Platform) | JetBrains
December 17, 2017 - But if you execute action "Run File in Console", it'll execute your file exactly in a Python Console and you'll have an access to the interactive console after program execution. Concerning 'runfile', no, unfortunately, it isn't possible to create a shortcut for a separate console command, but you can call it from Console's history.
🌐
GitHub
github.com › spyder-ide › spyder › issues › 5859
hide the 'runfile (...)' expression when running a python script from Spyder · Issue #5859 · spyder-ide/spyder
November 30, 2017 - Is there a way to hide the 'runfile (...)' expression when running a python script from Spyder? Because it clutters the console. Especially for programs with short outputs where I might want to compare the results of different runs, it g...
Author   Noomene
🌐
Python
docs.python.org › 3 › library › runpy.html
runpy — Locating and executing Python modules
Source code: Lib/runpy.py The runpy module is used to locate and run Python modules without importing them first. Its main use is to implement the-m command line switch that allows scripts to be lo...
🌐
Visual Studio Code
code.visualstudio.com › docs › python › run
Running Python code in Visual Studio Code
November 3, 2021 - Similar to how you can interact with the Python REPL outside of VS Code, you can open a terminal within VS Code and activate a Python REPL. To do so, you can search in the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)) for Python: Start Terminal REPL, which opens a terminal for the currently selected Python interpreter.
🌐
Python.org
discuss.python.org › python help
Run a Python file in Command Prompt - Python Help - Discussions on Python.org
December 21, 2023 - How to run a Python file in Windows Command Prompt using the imput command?
🌐
GitHub
github.com › spyder-ide › spyder › issues › 5861
Spyder gives "error NameError: name 'runfile' is not defined" on a valid python file. · Issue #5861 · spyder-ide/spyder
November 30, 2017 - Description What steps will reproduce the problem? Install spyder write a python file try to run it with spyder. Notice that runfile() is apparently no longer supported. What is the expected output? What do you see instead? My file to ex...
Author   PeterLeopold
🌐
Medium
medium.com › @evaGachirwa › running-python-script-with-arguments-in-the-command-line-93dfa5f10eff
Running Python script with Arguments in the command line | by Eva Mwangi | Medium
April 22, 2023 - The sys module provides functions and variables to manipulate Python’s runtime environment. Through sys.argv arguments are passed from the command line to the Python script.
🌐
Python documentation
docs.python.org › 3 › tutorial › interpreter.html
2. Using the Python Interpreter — Python 3.14.5rc1 documentation
Invoking the Interpreter: The Python interpreter is usually installed as/usr/local/bin/python3.14 on those machines where it is available; putting/usr/local/bin in your Unix shell’s search path mak...
🌐
Reddit
reddit.com › r/learnpython › how to i execute a .py file from the interpreter?
r/learnpython on Reddit: How to I execute a .py file from the interpreter?
June 6, 2021 -

I have been at this for an hour. I wrote the script, went line by line in interactive mode (without opening the file) and it worked perfectly. Now I'm trying to actually run the file from the python (>>>) interpreter so that I can interact with it directly. I'm in the right directory. I'm using both Powershell and Kali Linux. I was trying first with powershell, but since the course is Linux based, I switched to my Kali Linux VM. Same.

The course says "Hint: Use -i when executing the file in the terminal"

I can execute it from the terminal, but not interactively in the python interpreter.

Please have mercy on me. I've looked everywhere and exec() doesn't work.

exec(report.py)

NameError : name 'report' is not defined

If it matters, the code defines a function that uses csv to enter data into a list of tuples. The function takes one argument : a csv file. I did all the sololearn courses in python and am now working through https://github.com/dabeaz-course/practical-python .

I also took python for biologists, which was too easy. But it taught me to be proficient in using vim, and that's what I used to create the file.