ModuleNotFoundError: No module named 'pandas' (Problem with Python3.9)

Viewed 685

Initially, I ran experiments on python3, which supports Pandas perfectly. Since our lab recently upgraded the server to an RTX 3000 series GPU, it supports Python 3.9, not previous versions. For that, when I ran the tests in python3.9 (python3.9 code file.py), the following error occurred: ModuleNotFoundError: No module named 'pandas'

Then I ran 'pip install pandas' and found that the requirements had already been met; here's further information:

Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pandas in ./.local/lib/python3.6/site-packages (1.1.5)
Requirement already satisfied: pytz>=2017.2 in ./.local/lib/python3.6/site-packages (from pandas) (2021.1)
Requirement already satisfied: python-dateutil>=2.7.3 in ./.local/lib/python3.6/site-packages (from pandas) (2.8.2)
Requirement already satisfied: numpy>=1.15.4 in ./.local/lib/python3.6/site-packages (from pandas) (1.19.5)
Requirement already satisfied: six>=1.5 in ./.local/lib/python3.6/site-packages (from python-dateutil>=2.7.3->pandas) (1.15.0)

But when I ran the file again, I received the same issue: ModuleNotFoundError: No module named 'pandas'

How can we install solve this issue?

2 Answers

You need to make sure you are running pip with the correct python version. ./.local/lib/python3.6/site-packages in your error indicates that you are still using python3.6. If you are using IPython, you can type pip install pandas directly in the interactive mode (not in the terminal), which uses the proper Python version then. In general, I would create a virtual environment using /path/to/python39 -m venv ~/myvenv, then active it using source ~/myvenv/bin/activate and install packages then - especially if using a graphics card you may need different package versions for different projects.

According to my understanding, our lab server supports various Python versions, and I was executing my code files from a directory with a Python version of 3.6, which caused the issue. Therefore, we must either change our project directory to Python 3.9 and install Pandas there or use the following command as instructed here.

python3.9 -m pip install pandas
Related