Even though the usual
ModuleNotFoundError are much obvious, sometimes there is an extra package or in this case a different package to be installed in order to get the required module. The error this time being:
ModuleNotFoundError: No module named 'psycopg2'
Package and module are used interchangeably.
- Python 3
cd to your Python project virtual environment directory. For instance:
Step 2. Install the
pip install psycopg2-binary --user
- If the above command doesn’t work try replacing
This way we are running the module’s binary version. However, one could argue that using a binary packages in production is discouraged.
If you still want to install the
psycopg2 package the old-fashioned way (
pip install psycopg2), first you need to install few “build”, dependency packages. For instance:
apt-get install libpq-dev -y
Not necessarily, but there might be other one or more dependency packages that “just” works based on your working environment, of course, including:
- Resolve: “No module named <insert-package-name-here>” in Python.
- Resolve: “Resolve: "WARNING: The requested image’s platform (linux/amd64) does not match the detected host platform (linux/arm64/v8).
Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.