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')
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.
Create a project for an application called example.
uv init example
cd example
Install pydantic-ai
, including examples, as project dependency. Note the single quotation marks.
uv add 'pydantic-ai[examples]'
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