uv icon indicating copy to clipboard operation
uv copied to clipboard

Clarify that `uv run python` gets you a REPL

Open zanieb opened this issue 1 year ago • 3 comments

We could also provide another way to do this, eventually? Maybe just python when we have a shim. Maybe a bare uvx.

zanieb avatar Aug 23 '24 20:08 zanieb

@zanieb Updated the docs and added the uv run python section in docs/scripts.

Aditya-PS-05 avatar Sep 17 '24 13:09 Aditya-PS-05

I just have a question regarding the use of single scripts projects... So for example:

In: main.py

# /// script
# requires-python = ">=3.12"
# dependencies = [
#     "numpy",
#     "pandas",
# ]
# ///

import numpy
import pandas

def main():
    pass

if __name__ == '__main__':
    main()
    print('Done!')

Then using uv produces no errors:

user@pop-os:~/Documents/GitHub/standalone_scripts$ uv run main.py 
Reading inline script metadata from: main.py
Done!

However when trying to get a REPL after an execution (maybe inspect some variables or have imports ready):

user@pop-os:~/Documents/GitHub/standalone_scripts$ uv run python -i main.py
Traceback (most recent call last):
  File "/home/user/Documents/GitHub/standalone_scripts/main.py", line 9, in <module>
    import numpy
ModuleNotFoundError: No module named 'numpy'
>>> 

Michallote avatar Oct 10 '24 01:10 Michallote

@Michallote we just don't support that yet! i.e., we don't read the metadata because you invoked python not the script itself. We can track that at https://github.com/astral-sh/uv/issues/8064

zanieb avatar Oct 10 '24 01:10 zanieb

When I run uv run python, I get an interactive REPL as expected. However, changes to the source code aren’t reflected immediately — even re-importing the modules doesn’t help. I have to exit and restart the REPL to see the updates. The same issue occurs with ipython, even when using %autoreload. Is this expected behavior?

IliasAarab avatar Mar 21 '25 13:03 IliasAarab

@IliasAarab could you open a new issue with a minimal reproduction?

zanieb avatar Mar 21 '25 14:03 zanieb

@zanieb thanks for the response, see #12373

IliasAarab avatar Mar 21 '25 17:03 IliasAarab