0

I used to code in Jupyter notebook and importing pandas was never thrown an error. But when I use the same code in Visual Studio Code,

# Import Libraries

from random import seed
from random import randint
import pandas 
import numpy 
import math
import random
import collections 
import itertools
import collections
import matplotlib.pyplot as plt
import seaborn as sns
# %matplotlib inline

I receive the below error.

  File "g:/My Drive/M/importlibrary.py", line 5, in <module>
    import pandas
  File "C:\Users\M\Anaconda3\lib\site-packages\pandas\__init__.py", line 19, in <module>
    "Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']

I try to search for several similar issues and most of the solution ask to first uninstall and then install NumPy and Pandas using the below code,

pip3 uninstall pandas
pip3 uninstall numpy

However, I have followed this workaround but the problem did not resolve. The version of python that I am using is, Python 3.6.8 :: Anaconda, Inc.

Please help if you can.

monir zaman
  • 309
  • 1
  • 3
  • 13

2 Answers2

1

Is there a reason why you don't install Numpy/Pandas using anaconda (conda install -c anaconda numpy/pandas)? Did you run Jupyter from inside anaconda when it worked? I suggest going to terminal and figuring out where your modules are installed (i.e. if they are inside the anaconda folders, or somewhere where anaconda has access to).

In general, I'd advise against installing python packages for anaconda using pip, just use conda's package manager if you can. This question seems related. In your case, have you tried uninstalling the pip variant and reinstalling using conda?

Steven
  • 404
  • 1
  • 3
  • 10
  • Yes, the program works when I run the Jupyter from inside the anaconda. Also, for installing with pip, I tried from the location C:\Python36\Scripts. – monir zaman Jun 07 '20 at 11:34
0

The problem is resolved by uninstalling the Anaconda. I checked the control panel of the PC and found that there are multiple instances of python. VS Code uses Python 3.6.8 while Anaconda uses python 3.8. So, I uninstall 3.8, and then reinstall pandas,

pip3 uninstall pandas
pip3 install pandas

The error is no more.

monir zaman
  • 309
  • 1
  • 3
  • 13