pydantic / pydantic-extra-types

Extra Pydantic types.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I solve ModuleNotFoundError: No module named 'pydantic_extra_types'?

juandiegou opened this issue · comments

I am trying to import the module pydantic_extra_types and I get the error "from pydantic_extra_types.phone_numbers import PhoneNumber" ModuleNotFoundError: No module named 'pydantic_extra_types'
.....
....
from pydantic_extra_types.phone_numbers import PhoneNumber

class User(BaseModel):
...
....
phone_number : Union[PhoneNumber, None]=None

pydantic_extra_types

Selected Assignee: @lig

Hello @juandiegou can you share more context about this? any screenshot or logs

I have the module installed like this:
(env) C:\Users\JUANDIEGO\Desktop\PanaAPP>pip show pydantic_extra_types
Name: pydantic-extra-types
Version: 2.0.0
Summary: Extra Pydantic types.
Home-page:
Author:
Author-email: Samuel Colvin s@muelcolvin.com, Yasser Tahiri hello@yezz.me
License:
Location: C:\Users\JUANDIEGO\Desktop\PanaAPP\env\Lib\site-packages
Requires: pydantic
Required-by:

Captura

I run fast api and I get an error :

Process SpawnProcess-11:
Traceback (most recent call last):
File "C:\Python\Python311\Lib\multiprocessing\process.py", line 314, in _bootstrap
self.run()
File "C:\Python\Python311\Lib\multiprocessing\process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "C:\Python\Python311\Lib\site-packages\uvicorn_subprocess.py", line 76, in subprocess_started
target(sockets=sockets)
File "C:\Python\Python311\Lib\site-packages\uvicorn\server.py", line 60, in run
return asyncio.run(self.serve(sockets=sockets))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python\Python311\Lib\asyncio\runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "C:\Python\Python311\Lib\asyncio\runners.py", line 118, in run
return self.loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "C:\Python\Python311\Lib\site-packages\uvicorn\server.py", line 67, in serve
config.load()
File "C:\Python\Python311\Lib\site-packages\uvicorn\config.py", line 477, in load
self.loaded_app = import_from_string(self.app)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python\Python311\Lib\site-packages\uvicorn\importer.py", line 21, in import_from_string
module = importlib.import_module(module_str)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python\Python311\Lib\importlib_init
.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1204, in _gcd_import
File "", line 1176, in _find_and_load
File "", line 1147, in _find_and_load_unlocked
File "", line 690, in _load_unlocked
File "", line 940, in exec_module
File "", line 241, in call_with_frames_removed
File "C:\Users\JUANDIEGO\Desktop\PanaAPP\main.py", line 11, in
import router as routes
File "C:\Users\JUANDIEGO\Desktop\PanaAPP\router_init
.py", line 1, in
from .auth import *
File "C:\Users\JUANDIEGO\Desktop\PanaAPP\router\auth.py", line 8, in
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
^^^^^^^^^^^^
NameError: name 'CryptContext' is not defined
WARNING: WatchFiles detected changes in 'main.py'. Reloading...
Process SpawnProcess-12:
Traceback (most recent call last):
File "C:\Python\Python311\Lib\multiprocessing\process.py", line 314, in _bootstrap
self.run()
File "C:\Python\Python311\Lib\multiprocessing\process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "C:\Python\Python311\Lib\site-packages\uvicorn_subprocess.py", line 76, in subprocess_started
target(sockets=sockets)
File "C:\Python\Python311\Lib\site-packages\uvicorn\server.py", line 60, in run
return asyncio.run(self.serve(sockets=sockets))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python\Python311\Lib\asyncio\runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "C:\Python\Python311\Lib\asyncio\runners.py", line 118, in run
return self.loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "C:\Python\Python311\Lib\site-packages\uvicorn\server.py", line 67, in serve
config.load()
File "C:\Python\Python311\Lib\site-packages\uvicorn\config.py", line 477, in load
self.loaded_app = import_from_string(self.app)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python\Python311\Lib\site-packages\uvicorn\importer.py", line 21, in import_from_string
module = importlib.import_module(module_str)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python\Python311\Lib\importlib_init
.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1204, in _gcd_import
File "", line 1176, in _find_and_load
File "", line 1147, in _find_and_load_unlocked
File "", line 690, in _load_unlocked
File "", line 940, in exec_module
File "", line 241, in _call_with_frames_removed

(env) C:\Users\JUANDIEGO\Desktop\PanaAPP>uvicorn main:app --reload
INFO: Will watch for changes in these directories: ['C:\Users\JUANDIEGO\Desktop\PanaAPP']
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [2152] using WatchFiles
Process SpawnProcess-1:
Traceback (most recent call last):
File "C:\Python\Python311\Lib\multiprocessing\process.py", line 314, in _bootstrap
self.run()
File "C:\Python\Python311\Lib\multiprocessing\process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "C:\Python\Python311\Lib\site-packages\uvicorn_subprocess.py", line 76, in subprocess_started
target(sockets=sockets)
File "C:\Python\Python311\Lib\site-packages\uvicorn\server.py", line 60, in run
return asyncio.run(self.serve(sockets=sockets))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python\Python311\Lib\asyncio\runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "C:\Python\Python311\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "C:\Python\Python311\Lib\site-packages\uvicorn\server.py", line 67, in serve
config.load()
File "C:\Python\Python311\Lib\site-packages\uvicorn\config.py", line 477, in load
self.loaded_app = import_from_string(self.app)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python\Python311\Lib\site-packages\uvicorn\importer.py", line 24, in import_from_string
raise exc from None
File "C:\Python\Python311\Lib\site-packages\uvicorn\importer.py", line 21, in import_from_string
module = importlib.import_module(module_str)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1147, in _find_and_load_unlocked
File "", line 690, in load_unlocked
File "", line 940, in exec_module
File "", line 241, in call_with_frames_removed
File "C:\Users\JUANDIEGO\Desktop\PanaAPP\main.py", line 7, in
import router as routes
File "C:\Users\JUANDIEGO\Desktop\PanaAPP\router_init
.py", line 1, in
from .auth import *
File "C:\Users\JUANDIEGO\Desktop\PanaAPP\router\auth.py", line 5, in
from app.models import Token
File "C:\Users\JUANDIEGO\Desktop\PanaAPP\app\models_init
.py", line 2, in
from .user import *
File "C:\Users\JUANDIEGO\Desktop\PanaAPP\app\models\user.py", line 3, in
from pydantic_extra_types.phone_numbers import PhoneNumber
ModuleNotFoundError: No module named 'pydantic_extra_types'

I can't reproduce your exception with the following code:

from pydantic_extra_types.phone_numbers import PhoneNumber
from typing import Union
from pydantic import BaseModel


class User(BaseModel):
    phone_number: Union[PhoneNumber, None] = None

This issue is likely related to how your virtual environment is configured - not related to pydantic-extra-types.