matplotlib - ImportError with Python 3 -
i trying run example thinkstats2 code. copied github - file structure same given on github.
chap01soln.py __future__ import print_function import numpy np import sys import nsfg import thinkstats2 def readfemresp(dct_file='2002femresp.dct', dat_file='2002femresp.dat.gz', nrows=none): """reads nsfg respondent data. dct_file: string file name dat_file: string file name returns: dataframe """ dct = thinkstats2.readstatadct(dct_file) df = dct.readfixedwidth(dat_file, compression='gzip', nrows=nrows) cleanfemresp(df) return df def cleanfemresp(df): """recodes variables respondent frame. df: dataframe """ pass def validatepregnum(resp): """validate pregnum in respondent file. resp: respondent dataframe """ # read pregnancy frame preg = nsfg.readfempreg() # make map caseid list of pregnancy indices preg_map = nsfg.makepregmap(preg) # iterate through respondent pregnum series index, pregnum in resp.pregnum.iteritems(): caseid = resp.caseid[index] indices = preg_map[caseid] # check pregnum respondent file equals # number of records in pregnancy file if len(indices) != pregnum: print(caseid, len(indices), pregnum) return false return true def main(script): """tests functions in module. script: string script name """ resp = readfemresp() assert(len(resp) == 7643) assert(resp.pregnum.value_counts()[1] == 1267) assert(validatepregnum(resp)) print('%s: tests passed.' % script) if __name__ == '__main__': main(*sys.argv)
i getting importerror shown below:
traceback (most recent call last): file "c:\wamp\www\thinkstats_py3\chap01soln.py", line 13, in <module> import nsfg file "c:\wamp\www\thinkstats_py3\nsfg.py", line 14, in <module> import thinkstats2 file "c:\wamp\www\thinkstats_py3\thinkstats2.py", line 34, in <module> import thinkplot file "c:\wamp\www\thinkstats_py3\thinkplot.py", line 11, in <module> import matplotlib file "c:\python34\lib\site-packages\matplotlib\__init__.py", line 105, in <module> import 6 importerror: no module named 'six'
all files listed under src folder. no packages under src. tried adding packages nsfg , thinkstats error appeared. tried upgrading python 2.7 python 3.4. still getting same error. know need install 6 package matplotlib why getting import error on nsfg?
you getting import error on nsfg
because internally imports matplotlib (not directly, imports thinkstats2
, imports thinkplot
imports matplotlib
, has dependency on six
module) . , library not installed on computer, import fails.
most not have six
module , can try installing using - pip install six
.
or here, unzip , install using - python setup.py install
Comments
Post a Comment