ImportError despite successful installation in Python 3.9 venv
15:07 26 Mar 2026

I'm working in a Python 3.9 virtual environment on Ubuntu 20.04, and I'm getting an ImportError even though the package installed fine with pip.

The Setup:

  • Python: 3.9.7

  • OS: Ubuntu 20.04

  • Package: asyncpg

  • Virtual Env: venv

What I've Done:

  1. Set up a clean venv:

    1. python -m venv venv  
      source venv/bin/activate  
      
    2. Installed the package:

      pip install asyncpg  
      
    3. Confirmed the install:

      pip list  
      
    4. Verified the Python path:

      which python  # /path/to/venv/bin/python  
      which pip  # /path/to/venv/bin/pip  
      
    5. Package is present in site-packages.

    Error:

    ImportError: cannot import name 'asyncpg' from 'asyncpg'
    

    Code:

    import asyncpg
    
    async def fetch_data():
        conn = await asyncpg.connect(user='user', password='password', database='db')
        return await conn.fetch('SELECT * FROM my_table')
    

    Question:

    I can't figure out why it's not working. I’ve checked everything – no conflicting Python versions, package is installed, virtual environment is active. Anyone seen this before?

python