Closed xxxxxxbox closed 1 year ago
The last PydanticImportError in MVC project template can be fixed by updating line in requirements.txt from "pydantic" to "pydantic==1.10.10"
It seems that v2.0 (2023-06-30) of pydantic is not supporded by other packages in MVC project template.
Hi,
sorry for the delay in producing the documentation. I recently published the new project templates for version 2 of the framework.
I created a release with tag v1
for the project templates at the state that can be used with the documentation.
I started working on the documentation for v2, but today I dedicated a good deal of time to support Pydantic v2 in blacksheep version 2, and published this alpha release: https://github.com/Neoteroi/BlackSheep/releases/tag/v2.0a8.
If you wish to keep using version 1 of the web framework, which supports only Pydantic v1, please use the MVC template at tag v1: https://github.com/Neoteroi/BlackSheep-MVC/releases/tag/v1
Thank You for the heads up, @xxxxxxbox
Pydantic v2 was released on the 30th of June and these project templates are still a work in progress - I just released them a few days ago and I didn't release blacksheep
v2 as production stable, yet. I corrected the project templates pinning the dependencies as you pointed out. In the next days I will enrich them to support pydantic-settings
.
In the next days I will work on the documentation for blacksheep v2 and I will soon mark v2 production stable.
I have a hard following "Getting started with the MVC project template". https://www.neoteroi.dev/blacksheep/mvc-project-template/
Tutorial says to clone git repo https://github.com/Neoteroi/BlackSheep-MVC. After I cloned it I get folders like "{{cookiecutter.project_name}}" etc. So I figured out that I should use:
cookiecutter https://github.com/Neoteroi/BlackSheep-MVC or pip install blacksheep-cli blacksheep create --template mvc
After running "blacksheep create --template mvc" I have to answer 4 questions. And they are not all documented in tutorial. So I tried different combinations of answers.
After creating test MVC project with "blacksheep create --template mvc" my folder structure is not the same as in tutorial. And I have no server.py file and can't run the project with command from tutorial "uvicorn server:app --port 44777 --reload". It took some time by analyzing different repos at GitHub to figure out that I should now run project with "python dev.py"
Tutorial says that Python version 3.7, 3.8, 3.9, or 3.10 are supported. I had 3.9 but got errors. Project uses dataclasses with slots argument. "slots" are supported since python 3.10+. So I installed new version of python 3.11
Now I run python dev.py and get the following error:
PS Z:\dev\BlackSheep-MVC\black-mvc1> python dev.py Running for local development
Visit http://localhost:8000/ INFO: Will watch for changes in these directories: ['Z:\dev\BlackSheep-MVC\black-mvc1'] INFO: Uvicorn running on http://localhost:8000 (Press CTRL+C to quit) INFO: Started reloader process [16832] using StatReload Process SpawnProcess-1: Traceback (most recent call last): File "C:\Users\User1\AppData\Local\Programs\Python\Python311\Lib\multiprocessing\process.py", line 314, in _bootstrap self.run() File "C:\Users\User1\AppData\Local\Programs\Python\Python311\Lib\multiprocessing\process.py", line 108, in run self._target(*self._args, self._kwargs) File "Z:\dev\BlackSheep-MVC\venv\Lib\site-packages\uvicorn_subprocess.py", line 76, in subprocess_started target(sockets=sockets) File "Z:\dev\BlackSheep-MVC\venv\Lib\site-packages\uvicorn\server.py", line 61, in run return asyncio.run(self.serve(sockets=sockets)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\User1\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "C:\Users\User1\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\User1\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "Z:\dev\BlackSheep-MVC\venv\Lib\site-packages\uvicorn\server.py", line 68, in serve config.load() File "Z:\dev\BlackSheep-MVC\venv\Lib\site-packages\uvicorn\config.py", line 473, in load self.loaded_app = import_from_string(self.app) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "Z:\dev\BlackSheep-MVC\venv\Lib\site-packages\uvicorn\importer.py", line 24, in import_from_string raise exc from None File "Z:\dev\BlackSheep-MVC\venv\Lib\site-packages\uvicorn\importer.py", line 21, in import_from_string module = importlib.import_module(module_str) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\User1\AppData\Local\Programs\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 "Z:\dev\BlackSheep-MVC\black-mvc1\app\main.py", line 7, in
from app.auth import configure_authentication
File "Z:\dev\BlackSheep-MVC\black-mvc1\app\auth.py", line 3, in
from app.settings import Settings
File "Z:\dev\BlackSheep-MVC\black-mvc1\app\settings.py", line 9, in
from pydantic import BaseModel, BaseSettings
File "Z:\dev\BlackSheep-MVC\venv\Lib\site-packages\pydantic\ init.py", line 206, in getattr__
return _getattr_migration(attr_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "Z:\dev\BlackSheep-MVC\venv\Lib\site-packages\pydantic_migration.py", line 279, in wrapper
raise PydanticImportError(
pydantic.errors.PydanticImportError:
BaseSettings
has been moved to thepydantic-settings
package. See https://docs.pydantic.dev/2.0/migration/#basesettings-has-moved-to-pydantic-s** ettings for more details.For further information visit https://errors.pydantic.dev/2.0/u/import-error
PS Z:\dev\BlackSheep-MVC\black-mvc1> pip list
Package Version
annotated-types 0.5.0 arrow 1.2.3 binaryornot 0.4.4 blacksheep 2.0a7 blacksheep-cli 0.0.3 certifi 2023.5.7 cffi 1.15.1 chardet 5.1.0 charset-normalizer 3.1.0 click 8.1.3 colorama 0.4.6 cookiecutter 2.1.1 cryptography 38.0.4 essentials 1.1.5 essentials-configuration 2.0.3 essentials-openapi 1.0.7 guardpost 1.0.2 h11 0.14.0 httptools 0.5.0 idna 3.4 itsdangerous 2.1.2 Jinja2 3.1.2 jinja2-time 0.2.0 markdown-it-py 3.0.0 MarkupSafe 2.1.3 mdurl 0.1.2 pathvalidate 3.0.0 pip 22.3.1 prompt-toolkit 3.0.38 pycparser 2.21 pydantic 2.0 pydantic_core 2.0.1 Pygments 2.15.1 PyJWT 2.6.0 python-dateutil 2.8.2 python-dotenv 1.0.0 python-slugify 8.0.1 PyYAML 6.0 questionary 1.10.0 requests 2.31.0 rich 13.4.2 rich-click 1.6.1 rodi 2.0.2 setuptools 65.5.1 six 1.16.0 text-unidecode 1.3 typing_extensions 4.7.0 urllib3 2.0.3 uvicorn 0.22.0 wcwidth 0.2.6 websockets 10.4 wheel 0.38.4
Please consider updating tutorial and check if pydantic.errors.PydanticImportError can be fixed. Am I doing something wrong? How can I start tutorial project?