1

I’m running a Python project on a Raspberry Pi (Debian / Raspberry Pi OS, Python 3.9.2). The project has its own virtual environment (.venv), and I launch it with a script (alsv4) that starts multiple services using multiprocessing and uvicorn. I did "import pandas as pd" however, this error keeps showing. I am not using it yet but soon I will be. How can this be fixed?

I did "import pandas as pd" however, this error keeps showing. I am not using it yet but soon I will be. How can this be fixed?


    Traceback (most recent call last):
      File "/usr/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
        self.run()
      File "/usr/lib/python3.9/multiprocessing/process.py", line 108, in run
        self._target(*self._args, **self._kwargs)
      File "/home/rpi/Desktop/als-v4/main.py", line 32, in run_als_back_service
        uvicorn.run("src.services.ALS_back:app", host="0.0.0.0", port=port, reload=False)
      File "/home/rpi/Desktop/als-v4/.venv/lib/python3.9/site-packages/uvicorn/main.py",   
        line 580, in run
        server.run()
      File "/home/rpi/Desktop/als-v4/.venv/lib/python3.9/site-packages/uvicorn/server.py", 
        line 67, in run
        return asyncio.run(self.serve(sockets=sockets))
      File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
        return loop.run_until_complete(main)
      File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
        return future.result()
      File "/home/rpi/Desktop/als-v4/.venv/lib/python3.9/site-packages/uvicorn/server.py", 
        line 71, in serve
        await self._serve(sockets)
      File "/home/rpi/Desktop/als-v4/.venv/lib/python3.9/site-packages/uvicorn/server.py", 
        line 78, in _serve
        config.load()
      File "/home/rpi/Desktop/als-v4/.venv/lib/python3.9/site-packages/uvicorn/config.py", 
        line 436, in load
        self.loaded_app = import_from_string(self.app)
      File "/home/rpi/Desktop/als-v4/.venv/lib/python3.9/site-packages/uvicorn/importer.py", 
        line 22, in import_from_string
        raise exc from None
      File "/home/rpi/Desktop/als-v4/.venv/lib/python3.9/site-packages/uvicorn/importer.py",   
        line 19, in import_from_string
        module = importlib.import_module(module_str)
      File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
      File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 790, in exec_module
      File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
      File "/home/rpi/Desktop/als-v4/src/services/ALS_back.py", line 4, in <module>
        import pandas as pd
      ModuleNotFoundError: No module named 'pandas'

I have requirements-rpi.txt.

    annotated-types==0.7.0
    anyio==4.9.0
    certifi==2025.7.14
    charset-normalizer==3.4.2
    click==8.1.8
    exceptiongroup==1.3.0
    fastapi==0.116.1
    h11==0.16.0
    idna==3.10
    mfrc522==0.0.7
    numpy==2.0.2
    opencv-python==4.12.0.88
    pillow==11.3.0
    pydantic==2.11.7
    pydantic-core==2.33.2
    python-dotenv==1.1.1
    requests==2.32.4
    RPi.GPIO==0.7.1
    sniffio==1.3.1
    spidev==3.7
    starlette==0.47.1
    typing-extensions==4.14.1
    typing-inspection==0.4.1
    urllib3==2.5.0
    uvicorn==0.35.0
    pandas==2.3.2

Context:

Raspberry Pi 4 Model B
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

Python 3.9.2
pip 25.2 from /home/rpi/.local/lib/python3.9/site-packages/pip (python 3.9)
3
  • 1
    pip show /home/rpi/.local/lib/python3.9/site-packages/ but error show /home/rpi/Desktop/als-v4/.venv/lib/python3.9/site-packages which may suggest that you use wrong pip and it installs pandas for global version, not for venv. Did you activate venv before running pip? You may also use python -m pip ... to install it - but it also need to activate venv before installation Commented Sep 3 at 13:16
  • what do you have in script alsv4 ? If it is bash script then question is if it activates venv before running python code. Commented Sep 3 at 13:18
  • @furas I have done those actually but it did not work at all. What I did is I deleted the venv and made new one again. I did the installation of the requirements-rpi.txt again and it worked. Thank you for your response. Commented Sep 4 at 6:59

1 Answer 1

0

The most likely cause is that pandas is installed outside your venv.
So try this to setup your requirements in the right place:


cd /home/rpi/Desktop/als-v4
# activate your venv
. .venv/bin/activate
# update these..
python -m pip install --upgrade pip setuptools wheel
# Install your requirements inside your venv
python -m pip install -r requirements-rpi.txt

once done you can check your pandas and numpy quickly:

python -c "import pandas; print(pandas.__version__)"
python -c "import numpy; print(numpy.__version__)"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.