Python importerror no module named pandas

No module named pandas

I am new to python and I am trying to make a simple stock market program using pandas to import the data. I have installed Anaconda which said that it installed pandas along with it, as well as Python 2.7. I use PyCharm as my IDE. When I run:

import pandas as pd from pandas_datareader import data 
import pandas as pd ImportError: No module named pandas 

5 Answers 5

When entering the command to run your file, make sure you specify which version of python you’re using. For example, instead of python filename.py , use python3 filename.py or python2 filename.py

Try to install it using sudo .

for ubuntu . it worked got me. pip or pip3 .. as per your requirement.

You need to pip install pandas and things will work.

Let’s get back to first principles here. Open a command-line, type python, and then import pandas as pd do you get an error?

Your issue is that pandas is not installed locally on your computer. Luckily, this is a simple task to accomplish by opening up either a Terminal or Command Prompt (depending on your OS), and typing in the command pip install pandas . This will install pandas and you will be good to go!

The issue is that Anaconda installs a Python version of its own, and likely the Python version is Python 3. When you use PyCharm IDE as your editor, you are using another version of Python (Python2). For my Mac, Anaconda’s Python is installed under /anaconda3/bin and my default Python is installed under /usr/bin/python .

Читайте также:  Java set to list sort

I recommend you either config PyCharm to use Anaconda’s Python, or use Anaconda’s Jupyter your project. Jupyter is arguably a stronger tool considering that you are doing data analytics task.

Also, for Anaconda’s python, you shoud use conda install pandas instead of pip install pandas to install additional packages. This is not necessary this time since it’s already installed.

Whenever I go to the interpreters page on PyCharm to choose Anaconda, only python 2.7 and python expo and expo 2 appear. In finder I looked up anaconda and all I found was the application «anaconda navigator». Is this correct?

I don’t use PyCharm myself, so I’m not sure if the interpreter if working correctly. For Anaconda tho, you can open the Anaconda navigator from applications folder and open up Jupyter from there. It will use Anaconda’s Python by default.

The same error message appears in Jupyter notebook on anaconda. I am using the exact same code as listed above. Sorry to bother u 🙂

Hmm interesting. Maybe try pip freeze and conda list to see what you have in respective Python? Pandas should be installed when you installed Anaconda.

Источник

ImportError: No module named pandas. Pandas installed pip

By the way, I have Python 2 and Python 3 on my Mac. They are not the same directory, and I suspect the Python interpreter didn’t find the path of Pandas.

i agree with you all,i use python3 when running programs while backage in one directory named python2.6, but i don’t know how to change that

It may be helpful to begin using virtual environments. Alternatively, you could install Pandas for Python 3 using pip3 install pandas .

7 Answers 7

First of all, install virtualenv inside your project folder to secure your project directory to avoid conflict with your other packages.

After installing this, run this command one by one inside your root project directory:

virtualenv venv source venv/bin/activate 

Now your directory is secure and you can install your required packages inside.

and others as you required.

Because you have installed virtualenv and running as secure, it will not conflict with other outside packages.

Use these all steps one by one.

Try to install Pandas using pip and pip3:

pip install pandas pip3 install pandas 

A suggestion: Use pyenv and set a Python version for your local directory.

If Python 2.7 is already installed, then to install NumPy and Pandas for v2.7, run the below commands:

sudo apt-get install python-numpy sudo apt-get install python-pandas 

If Python 3 is already installed, then to install NumPy and Pandas for v3, run the below commands:

sudo apt-get install python3-numpy sudo apt-get install python3-pandas 

On ubuntu, «sudo apt-get install python3-pandas» worked. Why is that? This is so frustrating wasting so many hours trying to find stuff only on stackoverflow.

I had Python 2 and Python 3 installed in different directories, but I was facing this error, because when I was using the command pip install pandas , it was installing Pandas in Python 2 directories while I was using Python 3.

So I had two directories with Python2 —> C:\Python27 and Python365 —> C:\Python365 .

Run pip install pandas in cmd . If library Pandas is already installed, you’ll see something like the following.

pip install pandas Requirement already satisfied: pandas in c:\python27\lib\site-packages (0.23.4) Requirement already satisfied: python-dateutil>=2.5.0 in c:\python27\lib\site-packages (from pandas) (2.7.3) Requirement already satisfied: numpy>=1.9.0 in c:\python27\lib\site-packages (from pandas) (1.14.4) Requirement already satisfied: pytz>=2011k in c:\python27\lib\site-packages (from pandas) (2018.4) Requirement already satisfied: six>=1.5 in c:\python27\lib\site-packages (from python-dateutil>=2.5.0->pandas) (1.11.0) 

From the output of above command you can see that pandas is installed in the Python2 directory, i.e. C:\python27\lib\site-packages (0.23.4).

Run the python command in cmd to check which Python version are you running.

python Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. 

You can see that I’m using Python3 while Pandas is installed in the Python2 directory.

To install Pandas and other libraries in Python3 go to the scripts folder in Python3 directory, i.e., C:\Python365\Scripts . Open a Command window and run pip install pandas .

Or you can use the complete path of pip in the Python3 directory in cmd to run the install command, i.e., C:\Python365\Scripts\pip install pandas

Источник

ModuleNotFoundError: No module named ‘pandas’

C:\Users\myPC\PycharmProjects\myPythonApps\venv\Scripts\python.exe
C:/Users/myPC/PycharmProjects/myPythonApps/PI-regulator Traceback (most recent call last): File «C:/Users/myPC/PycharmProjects/myPythonApps/PI-regulator», line 19, in import pandas as pd ModuleNotFoundError: No module named ‘pandas’

C:\Windows\System32>pip install pandas 
Requirement already satisfied: pandas in c:\users\mypc\appdata\local\programs\python\python36-32\lib\site-packages Requirement already satisfied: python-dateutil>=2 in с:\users\mypc\appdata\local\programs\python\python36-32\lib\site-packages (from pandas) Requirement already satisfied: numpy>=1.9.0 in c:\users\mypc\appdata\local\programs\python\python36-32\lib\site-packages (from pandas) Requirement already satisfied: pytz>=2011k in c:\users\mypc\appdata\local\programs\python\python36-32\lib\site-packages (from pandas) Requirement already satisfied: six>=1.5 in c:\users\mypc\appdata\local\programs\python\python36-32\lib\site-packages (from python-dateutil>=2->pandas) C:\Windows\System32> 
C:\Users\myPC\PycharmProjects\myPythonApps\venv\Scripts\python.exe C:/Users/myPC/PycharmProjects/myPythonApps/PI-regulator Traceback (most recent call last): File "C:/Users/myPC/PycharmProjects/myPythonApps/PI-regulator", line 19, in import pandas as pd ModuleNotFoundError: No module named 'pandas' Process finished with exit code 1 

Источник

ModuleNotFoundError: No module named ‘pandas’

I had this problem as well and tried a few different things until I realized my python path under settings.json (python.pythonPath) was incorrect and pointing to the wrong directory. The path should be to where the Python.exe file is under programs.

To make sure that you’re using the same pip as your python , execute the pip with whole path from python directory i.e.

C:\Program Files\Anaconda3\lib\site-packages (python 3.6)\pip install pandas 

This will install the pandas in the same directory

Or C:\Python365\pip install pandas Or C:\Python27\pip install pandas 

Whichever Python you wand to use and install the pandas

If you want to use a specific version of Python in Windows cmd , just add the path of that Python in System Variables .

For python 3.7, type following in CMD:

CD C:\Users\[path]\Continuum\anaconda3\Lib\site-packages 

In my case, I installed panda instead of pandas . My installation was missing the last letter s .

My problem was running pandas from an ipython shell. The error message from the original post kept cropping up, despite having pandas installed. Then I started reading messages (see below). Installing ipython in the virtual environment didn’t help, BUT deactivating the virtual environment and activating it again did.

➜ ipython /. /python3.10/site-packages/IPython/core/interactiveshell.py:887: UserWarning: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv. 

Источник

Оцените статью