简体   繁体   中英

Unable to import Pandas_Datareader

I'm using Python 3.6 in Ubuntu 16.04.

From this very simple program:

import pandas_datareader.data as web
import datetime
amzn = web.DataReader("AMZN", "yahoo", datetime(2000,1,1), datetime(2015,1,1))

I get this very impressive error list:

 Traceback (most recent call last):
File "/SAT/time_series.py", line 1, in <module>
import pandas_datareader.data as web
File "/anaconda/lib/python3.6/site-packages/pandas_datareader/__init__.py", line 3, in <module>
from .data import (get_components_yahoo, get_data_famafrench, get_data_google, get_data_yahoo, get_data_enigma,  # noqa
File "/anaconda/lib/python3.6/site-packages/pandas_datareader/data.py", line 7, in <module>
from pandas_datareader.google.daily import GoogleDailyReader
File "/anaconda/lib/python3.6/site-packages/pandas_datareader/google/daily.py", line 1, in <module>
from pandas_datareader.base import _DailyBaseReader
File "/anaconda/lib/python3.6/site-packages/pandas_datareader/base.py", line 3, in <module>
import numpy as np
File "/anaconda/lib/python3.6/site-packages/numpy/__init__.py", line 146, in <module>
from . import add_newdocs
File "/anaconda/lib/python3.6/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/anaconda/lib/python3.6/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/anaconda/lib/python3.6/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/anaconda/lib/python3.6/site-packages/numpy/core/__init__.py", line 72, in <module>
from numpy.testing.nosetester import _numpy_tester
File "/anaconda/lib/python3.6/site-packages/numpy/testing/__init__.py", line 10, in <module>
from unittest import TestCase
File "/anaconda/lib/python3.6/unittest/__init__.py", line 64, in <module>
from .main import TestProgram, main
File "/anaconda/lib/python3.6/unittest/main.py", line 4, in <module>
import argparse
File "/SAT/argparse.py", line 1
if len(sys.argv) &gt; 1:
                    ^
SyntaxError: invalid syntax

I've really now idea what is causing this error other than it's occurring when the program tries to import pandas_datareader.

I am new to the data_reader but I'm pretty sure the import command is syntactically correct.

Can anyone suggest what the problem is?

I think you have shadowed Python module argparse with your own /SAT/argparse.py .

/anaconda/lib/python3.6/unittest/main.py in line 4 tries to import argparse (the standard Python module), but your module (which has an error len(sys.argv) &gt; 1: ) jumps in first.

Try to rename /SAT/argparse.py to /SAT/my_argparse.py

PS try to name your own scripts and directories differently so that they don't shadow stardard Python modules

Try this:

import datetime

import pandas_datareader.data as web

amzn = web.DataReader("AMZN", "yahoo", datetime.datetime(2000,1,1), datetime.datetime(2015,1,1))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM