Use the Ctrl+Shift+P command, search for and select Python:Select Interpreter(Or click directly on the python version displayed in the lower right corner), and select the correct interpreter.

No module named 'pydantic_core._pydantic_core' using AWS Lambdas
help, getting this error message ImportError: cannot import name 'Undefined' from 'pydantic.fields'
python - Why can't the import be resolved? - Stack Overflow
python - ModuleNotFoundError: No module named 'pydantic' - Stack Overflow
Hi, my Oobabooga installation suddenly stop working today. It was working fine yesterday and today I am getting this error:
ImportError: cannot import name 'Undefined' from 'pydantic.fields' E:\Oobabooga\installer_files\env\lib\site-packages\pydantic\fields.py)
I am on windows and don't know much about linux or python. I already tried update a couple of times and it's saying I am up to date. Any idea for a quick fix?
Use the Ctrl+Shift+P command, search for and select Python:Select Interpreter(Or click directly on the python version displayed in the lower right corner), and select the correct interpreter.

ok this issue is definitely with the chose python interpreter.
- check what is the version of python you are using
- check whether you are using wsl on windows or linux or command prompt
now in my case choose the interpreter was not solving the issue. I even tried the virtual environment and giving a path. but python by default was installing the .exe in a hidden folder and i couldn't find the files in the env folder
i was using wsl on windows and visual studio code.
so i ran pip installed outside the env. and also on the powershell/cmd and the terminal. and the error went away.
I have a project setup as follows:
├── khorne │ ├── Dockerfile │ ├── Makefile │ ├── pyproject.toml │ ├── requirements-qa.txt │ ├── requirements.txt │ ├── src │ │ └── domain │ │ ├── __init__.py │ │ ├── entities.py │ │ ├── events.py │ │ ├── services.py │ │ └── values.py | ├── .venv
Inside the pyproject.toml there is a section for pyright:
[tool.pyright]
include = ["src"]
executionEnvironments = [
{ root = "src" }
]
LspInfo shows the correct root directory: /home/jakov/Projects/metaflaff/khorne
However when I import e.g. pydantic I get the message Import pydantic could not be resolved
However however, if I do source .venv/bin/activate and THEN open neovim the path is correctly resolved.
This will be limiting when working with multi root projects. I use default settings for pyright.
Does anyone have an idea what the root cause could be?
Problem
I'm facing an issue when trying to run a Python script that uses the openai library. Here's the traceback I get:
Traceback (most recent call last):
File "script_path\generate.py", line 4, in <module>
import openai
File "python_installation_path\Lib\site-packages\openai\__init__.py", line 8, in <module>
from . import types
File "python_installation_path\Lib\site-packages\openai\types\__init__.py", line 5, in <module>
from .batch import Batch as Batch
File "python_installation_path\Lib\site-packages\openai\types\batch.py", line 7, in <module>
from .._models import BaseModel
File "python_installation_path\Lib\site-packages\openai\_models.py", line 24, in <module>
from pydantic.fields import FieldInfo
File "python_installation_path\Lib\site-packages\pydantic\fields.py", line 17, in <module>
from pydantic_core import PydanticUndefined
File "python_installation_path\Lib\site-packages\pydantic_core\__init__.py", line 6, in <module>
from ._pydantic_core import (
...<22 lines>...
)
ModuleNotFoundError: No module named 'pydantic_core._pydantic_core'Context:
Python version: 3.13 (installed system-wide on Windows 11, 64-bit at C:\Program Files\Python313).
The libraries, including
openai,pydantic, andpydantic_core, are installed using admin cmd with pip and appear in the correctLib\site-packagesdirectory.The file
_pydantic_core.cp313-win_amd64.pydis present in thepydantic_corefolder, but the error persists.
What I've Tried:
pip uninstall pydantic pydantic_core openai pip install pydantic pydantic_core openai
I don't quite understand the context here. There has also been a problem with annotated-types in connection with OpenAI.
pip show pydantic_core Name: pydantic_core Version: 2.27.2 ... Location: C:\Program Files\Python313\Lib\site-packages Requires: typing-extensions Required-by: pydantic C:\Windows\System32>pip install pydantic_core Requirement already satisfied: pydantic_core in c:\program files\python313\lib\site-packages (2.27.2) Requirement already satisfied: typing-extensions!=4.7.0,>=4.6.0 in c:\program files\python313\lib\site-packages (from pydantic_core) (4.12.2)
Everything looks correct to me, doesn't it? Then why does it keep failing?
This is a common problem with binary/C extensions. For further details, check here: (Pylint & C extensions)
To fix it, you need to add the following to .pylintrc file (You can add this file to your current project folder if you like)
[MASTER]
extension-pkg-allow-list=pydantic
Note that switching to mypy (as suggested by another answer here) is not the right approach since pylint & mypy are two different things (the former is a linter while the latter is sort of a type checker)
The first thing that you noticed
pydantic BaseModel not found in Fastapi
is related to your linter.
I got the same warning when my linter was pylint, so I changed the linter from pylint to mypy and the problem disappeared.
Install mypy via pip
pip install mypyOpen the command palette in VScode
Ctrl+Shift+PType this in command palett:
Python: Select LinterThen Select
mypyin the list of linters