Home > Software engineering >  Pandas not found, although installed via Anaconda and seeming to work in debug console
Pandas not found, although installed via Anaconda and seeming to work in debug console

Time:08-07

I have created a conda environment to manipulate existing excel files using the pandas library. Unfortunately, already the first line of code is giving me a headache:

When I import pandas via import pandas as pd I get the following error message: ModuleNotFoundError: No module named 'pandas'. I get the same error message when I execute my python file using the conda base environment.

I have already searched the web for half a day, reading articles that more or less all say the same thing: if you get this error message, it means that pandas is not installed properly in your environment. However, I have already checked this multiple times for both my custom conda environment as well as for the base environment and pandas is definitely installed. Moreover, when I enter debug mode, the pd.read_excel() function does work and returns a printable data frame...

I would be really grateful for any help/suggestions!!!

N.B. I'm using studio code on an M1 Mac.

CodePudding user response:

You can try using venv. It is a standard python library to create lightweight environments.

To use you can do:

python3 -m venv my_environment
source my_environment/bin/activate
pip install pandas

Then you can try and run your program to see if this would work.

CodePudding user response:

In VS Code make sure the right python interpreter is selected, it should be from your conda env you have defined (this helps with the linting, if pandas not found it will highlight the import pandas line)

Shift   Cmd   P > Python: Select Interpreter

Then, in terminal check you are using python from the conda environment you have created

where python

If all is fine and it's still not working, then re-create conda environment as follows -

conda create --name pandas_env --python=3.8 pip
conda activate pandas_env
pip install pandas

I hope this helps.

  • Related