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'
-
2did you install pandas?ashish14– ashish142019年09月30日 12:29:13 +00:00Commented Sep 30, 2019 at 12:29
-
2Possible duplicate of How to install pandas for Python 3?Prathik Kini– Prathik Kini2019年09月30日 12:32:13 +00:00Commented Sep 30, 2019 at 12:32
-
Possible duplicate of ImportError: No module named pandaskoen– koen2019年09月30日 13:45:18 +00:00Commented Sep 30, 2019 at 13:45
3 Answers 3
try below code to install pandas.
sudo pip3 install pandas
Above code work for me .
Comments
Try installing with this:
pip install pandas
If the install fails due to lacking privilege, do this:
sudo pip install pandas
Note: You may have to use pip3 is your default Python version is 2.X
Comments
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.
Creating the Environment
On Linux/Mac OS
$ python3 -m venv [name of environment]
On Windows
PS> python -m venv [name of environment]
Activating the Environment
On Linux/Mac OS
$ source [name of environment]/bin/activate
On Windows
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?