简体   繁体   中英

Python yahoo-finance package ImportError: cannot import name Share

I am using Python2.7 and I try to use python yahoo-finance package on mac to get some data

from yahoo_finance import Share
yahoo = Share('YHOO')
print yahoo.get_open()

but it shows error message: "ImportError: cannot import name Share"

I use sudo pip install to install yahoo-finance and below is the pip install info:

Metadata-Version: 2.0
Name: yahoo-finance
Version: 1.2.1
Summary: Python module to get stock data from Yahoo! Finance
Home-page: https://github.com/lukaszbanasiak/yahoo-finance
Author: Lukasz Banasiak
Author-email: lukasz@banasiak.me
Installer: pip
License: MIT
Location: /Users/Singsing/anaconda/lib/python2.7/site-packages
Requires: pytz, simplejson

I look up and try the code in this link: Trouble importing yahoo finance to python

import os
import sys

try:
    user_paths = os.environ['PYTHONPATH'].split(os.pathsep)
except KeyError:
    user_paths = []

print "PYTHONPATH: ", user_paths
print "sys.path: ", sys.path

My PythonPath is [] as result, I also try

export PYTHONPATH=$PYTHONPATH:"/Users/anaconda/lib/python2.7/site-packages" which is my pip install location but it doesn't work either.

Can someone tell me what's wrong? Thanks in advance!

在此处输入图片说明

在此处输入图片说明 If you chekc pypi, you will see people usually use pandas to read data directly: following links is documentation of how to read data from yahoo finance/google finance through pandas:

http://pandas.pydata.org/pandas-docs/version/0.18.1/remote_data.html?highlight=yahoo

You can get more data than you expected~

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