-
First Check
Commit to Help
Example Codepip insall fastapi
>>> print(fastapi.__version__)
0.87.0
>>> from fastapi.testclient import TestClient
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\ProgramData\Anaconda3\lib\site-packages\fastapi\testclient.py", line 1, in <module>
from starlette.testclient import TestClient as TestClient # noqa
File "C:\ProgramData\Anaconda3\lib\site-packages\starlette\testclient.py", line 15, in <module>
import httpx
ModuleNotFoundError: No module named 'httpx' DescriptionGetting error ModuleNotFoundError: No module named 'httpx' while import TestClient from fastapi.testclient. Operating SystemWindows Operating System DetailsNo response FastAPI Version0.87.0 Python Version3.8 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 1 reply
-
Yes, starlette has changed the TestClient to use HTTPX instead of requests and 0.87.0 upgrades starlette. https://github.com/tiangolo/fastapi/releases/tag/0.87.0 The docs have been updated here https://fastapi.tiangolo.com/tutorial/testing/ to reflect the change. |
Beta Was this translation helpful? Give feedback.
-
Just do If the solution above works for you, please close the issue. 😊 |
Beta Was this translation helpful? Give feedback.
-
Yep, install HTTPX, that's it 🚀 |
Beta Was this translation helpful? Give feedback.
-
@tiangolo I think there's something wrong with installing Solution: For the conda users: there is a @tiangolo I noticed there is no |
Beta Was this translation helpful? Give feedback.
-
yeah we use tool like pants which relies on transitive dependencies being explicit and hence it complains that it can't find |
Beta Was this translation helpful? Give feedback.
-
You don't have to manually install if you had used Also, since On a side note, it was clearly mentioned in release notes of both |
Beta Was this translation helpful? Give feedback.
-
In terms of best practices, does it seem reasonable to put 'fastapi[all]' in requirements-dev.txt but just 'fastapi' in requirements.txt, so that additional libraries needed for testing are only pulled in development mode? That's my new approach. |
Beta Was this translation helpful? Give feedback.
-
@pamelafox if you use a package manager like poetry, pdm, or pipenv, you can specify development dependencies so that you can exclude certain dependencies from production instances. |
Beta Was this translation helpful? Give feedback.
-
FWIW I'm not satisfied by the suggested answer here. When I install a package I should expect that package to install its own dependencies by default. If a more comprehensive installation statement is absolutely required then it should be included in the documentation. |
Beta Was this translation helpful? Give feedback.
-
I agree with this. Meanwhile, I think the current approach with fastapi is ok: it leaves the entry to some features open, while you get a message that you need to install extra things when you want to use that. (Feel like some in-app purchases 😂 ). In a fresh install of fastapi==0.112.1, I get
So httpx is still not included by default. However, for those who do not want to install |
Beta Was this translation helpful? Give feedback.
Just do
pip install httpx
orpip install fastapi[all] —upgrade
If the solution above works for you, please close the issue. 😊