Search code examples
pythonpandasanacondacondapython-import

Pandas not found, although installed via Anaconda and seeming to work in debug console


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.


Solution

  • 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.