I am trying to import pandas on Python (Linux) but it is giving me the following error:
ModuleNotFoundError
Traceback (most recent call last) in () 1 import pandas as pd ModuleNotFoundError: No module named 'pandas'
I am trying to import pandas on Python (Linux) but it is giving me the following error:
ModuleNotFoundError
Traceback (most recent call last) in () 1 import pandas as pd ModuleNotFoundError: No module named 'pandas'
You should never install Python packages using sudo as it's a potential security risk. Instead, you should install packages in a virtual environment.
Here's how to create and activate a virtual environment using Python's built-in venv module.
$ python3 -m venv [name of environment]
PS> python -m venv [name of environment]
$ source [name of environment]/bin/activate
PS> [name of environment]\Scripts\activate
Once you have your virtual environment active you can install pandas using
pip install pandas and import it as usual in your program.
For more information on working with virtual environments read this: How Can You Work With a Python Virtual Environment?