无法导入Pandas_Datareader

时间:2018-01-14 18:39:07

标签: python python-3.x pandas pandas-datareader

我在Ubuntu 16.04中使用Python 3.6。

从这个非常简单的程序:

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

我得到了这个令人印象深刻的错误列表:

 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

我现在真的知道导致此错误的原因除了程序尝试导入pandas_datareader时发生的错误。

我是data_reader的新手,但我非常确定import命令在语法上是正确的。

有人能说出问题是什么吗?

2 个答案:

答案 0 :(得分:4)

我认为您已使用自己的argparse隐藏了Python模块/SAT/argparse.py

第4行中的

/anaconda/lib/python3.6/unittest/main.py尝试导入argparse(标准Python模块),但您的模块(错误len(sys.argv) &gt; 1:)会先跳转。

尝试将/SAT/argparse.py重命名为/SAT/my_argparse.py

PS尝试以不同方式命名您自己的脚本和目录,以便他们不会影响标准Python模块

答案 1 :(得分:-2)

试试这个:

import datetime

import pandas_datareader.data as web

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