Fix the error: cannot import name 'MultiHostDsn' from 'pydantic.networks'

The error message ‘cannot import name multihostdsn from pydantic.networks’ is caused for the new Pydantic v2 conflicting with the Pydantic v1. Fix it by reading this post!

This is aPydantic networks import error message. Github PR closing it

Great work has been accomplished by the Pydantic, FastAPI, and related communities during the release of Pydantic v2, with a strong emphasis on compatibility.

However, there is a recurring issue that has surfaced among users of Gradio and Hugging Face. This issue pertains to the import error related to Pydantic networks.

The message cannot import name multihostdsn from pydantic.networks is due of this v1 and v2 compatibility. It is easily solved by upgrading your Pydantic version to v1.10 or more, or migrating to Pydantic v2 if you organization / project is still not prepared for that major release migration.

Solve the Pydantic error with Poetry: cannot import name MultiHostDsn from

As it is a rule in this blog, let’s jump quick to the solution and write a few lines of code that should solve your problem. For example, if your using poetry as your dependencies manager, you can add the Pydantic package in its v1 version, v1.10 minor version and the latest patch v.10.1 till the latest (currently v.1.10.13 is the latest version). More about package Semantic Versioning convention here.

To solve this error while using Poetry, just enter this in the terminal and the poetry project folder:

poetry add pydantic=^1.10

Then, you can check you Pydantic package version from the poetry.lock as:

poetry show pydantic

or even

poetry show pydantic | awk '/version { print $3 }'

If the change is not occurring and the env get stuck, you can always drop your environment, clear cache (shouldd’t be required) and lock/install again the pyproject file.

Solve the error with Pip ot Pipenv: cannot import name MultiHostDsn from

If you are using pip/pipenv you can easily do:

pip install --upgrade pydantic==1.10.*

If you are interested in more info, you can check the GitHub issue conversation and the PR fixing the problem that has been included in the >=1.10 release.

Carlos Vecina
Carlos Vecina
Senior Data Scientist at Jobandtalent

Senior Data Scientist at Jobandtalent | AI & Data Science for Business