3

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

I receive the error message

import pandas as pd

ImportError: No module named pandas

I am not sure why it is giving me this error message so any help would be greatly appreciated

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Cachario
  • 41
  • 1
  • 1
  • 6
  • 4
    Have you set the proper project interpreter in Pycharm? – user3483203 Aug 06 '18 at 03:01
  • Possible duplicate of [ImportError: No module named 'pandas'](https://stackoverflow.com/questions/38061426/importerror-no-module-named-pandas) –  Aug 06 '18 at 04:07

5 Answers5

2

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

Wilfred Ruck
  • 109
  • 1
  • 9
1

Try to install it using sudo ...

sudo pip3 install pandas

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

M. D. P
  • 604
  • 2
  • 6
  • 18
0

You need to pip install pandas and things will work.

hd1
  • 33,938
  • 5
  • 80
  • 91
  • I just did that and PyCharm still displays the same error message. – Cachario Aug 06 '18 at 11:07
  • 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? – hd1 Aug 06 '18 at 21:36
  • yes: python import pandas as pd gives me a syntax error and then – Cachario Aug 06 '18 at 21:51
  • python then on the next line import pandas as pd gives me "python" is not defined – Cachario Aug 06 '18 at 21:52
  • where's python installed? – hd1 Aug 06 '18 at 23:50
  • locally. I am not sure exactly where in my folders but I installed it directly off the python website, the same with anaconda – Cachario Aug 06 '18 at 23:54
  • Can you find it or whatever the windows equivalent is? – hd1 Aug 07 '18 at 00:06
  • Python is at usr/bin/Python – Cachario Aug 07 '18 at 00:16
  • and Anaconda is at Anaconda2/bin/python – Cachario Aug 07 '18 at 00:17
  • I have changed my interpreter to anaconda on pycharm and downloaded the panda package on the pycharm application. it only worked for one run then does not displays the same module error as before. the same thing happened when i ran pip install pandas when my interpreter was python 2.7 on pycharm – Cachario Aug 07 '18 at 03:34
  • Anaconda uses conda, so for that, you may need to `Anaconda2/bin/conda install pandas`. Now type `Anaconda2/bin/python` and type `import pandas as pd`. Your ImportError should be gone now. – hd1 Aug 07 '18 at 05:20
  • I think that would work but what would the code look like? Mine is: 'from Anaconda2/bin/python import pandas as pd'. It is now returning a syntax error on the '/' and I still am not sure if it is still importing pandas because I can only view one error message at a time – Cachario Aug 07 '18 at 11:09
  • Get out, back into the command prompt and try the Anaconda commands again – hd1 Aug 07 '18 at 14:43
  • It said "all requested packages are already installed". I then went back into my IDE and tried the commands again only to display the same syntax error message for the '/'s – Cachario Aug 07 '18 at 17:16
  • Ok, so you can load the right python? Type `import pandas as pd` – hd1 Aug 07 '18 at 20:55
  • The same error message still displays in pycharm but not in the terminal – Cachario Aug 07 '18 at 22:27
  • Point PyCharm to Anaconda's python? – hd1 Aug 08 '18 at 01:28
  • I have also done that and locally installed pandas and pandas_datareader and still the same error messages – Cachario Aug 08 '18 at 02:04
  • Clearly something else is wrong here, chat me up, share your screen and I'd be happy to take a look. – hd1 Aug 08 '18 at 04:14
  • I figured out why. I have the free version of PyCharm and the scientific tools such as pandas, matplotlib and numpy can only be used is the paid version. Simple fix but thanks for all of your time and help anyways. – Cachario Aug 08 '18 at 10:41
0

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!

James
  • 1,928
  • 3
  • 13
  • 30
0

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.

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.

Martin Liu
  • 107
  • 4
  • 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? – Cachario Aug 06 '18 at 10:25
  • 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. – Martin Liu Aug 06 '18 at 10:31
  • The same error message appears in Jupyter notebook on anaconda. I am using the exact same code as listed above. Sorry to bother u :) – Cachario Aug 06 '18 at 10:41
  • 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. – Martin Liu Aug 07 '18 at 02:52