python - uv run -m pydantic_ai_examples.pydantic_model error: unexpected argument '-m' found - Stack Overflow

admin2025-05-02  1

I have installed pydantic_ai

$ uv run -m pydantic_ai_examples.pydantic_model
error: unexpected argument '-m' found

I initialized with

$ uv add pydantic_ai
$ uv add pydantic_ai[examples] 
$ uv build

Still get unexpected argument -m error? Also tried this w/o uv and got:

$ python -m pydantic_ai_examples.pydantic_model
/Users/dev/anaconda3/bin/python: Error while finding module specification for 'pydantic_ai_examples.pydantic_model' (ModuleNotFoundError: No module named 'pydantic_ai_examples')

I have installed pydantic_ai

$ uv run -m pydantic_ai_examples.pydantic_model
error: unexpected argument '-m' found

I initialized with

$ uv add pydantic_ai
$ uv add pydantic_ai[examples] 
$ uv build

Still get unexpected argument -m error? Also tried this w/o uv and got:

$ python -m pydantic_ai_examples.pydantic_model
/Users/dev/anaconda3/bin/python: Error while finding module specification for 'pydantic_ai_examples.pydantic_model' (ModuleNotFoundError: No module named 'pydantic_ai_examples')
Share Improve this question edited Jan 2 at 9:22 InSync 11.2k4 gold badges18 silver badges56 bronze badges asked Jan 2 at 5:01 DracoDraco 535 bronze badges 0
Add a comment  | 

2 Answers 2

Reset to default 0

Given that you are using uv add, it seems you are using uv to manage an application or library project, in contrast to only using a virtual environment.

In this case, a full example might look as follows.

  1. Create a project for an application called example.

    uv init example
    cd example
    
  2. Install pydantic-ai, including examples, as project dependency. Note the single quotation marks.

    uv add 'pydantic-ai[examples]'
    
  3. Run the pydantic_model example.

    uv run -m pydantic_ai_examples.pydantic_model
    

The example will likely fail as no OpenAI API key is set yet. This can be fixed by setting the OPENAI_API_KEY environment variable.

It looks like you are running an old version of uv: the -m flag was added to uv run in version 0.4.18, released on 2024-10-02.

If you don’t want to install a new version of uv you can work around this by running the following instead of uv run -m …:

uv run python -m pydantic_ai_examples.pydantic_model
转载请注明原文地址:http://www.anycun.com/QandA/1746133630a92039.html