想要用 Python 的 pygeoip 库通过 ip 获取经纬,然后给百度地图,在页面显示,结果在形成对象这儿卡住了 各位大佬,帮吗看一下是啥情况? - V2EX
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Yycreater

想要用 Python 的 pygeoip 库通过 ip 获取经纬,然后给百度地图,在页面显示,结果在形成对象这儿卡住了 各位大佬,帮吗看下是啥情况?

  •  
  •   Yycreater
    Yycreater Jul 26, 2018 3518 views
    This topic created in 2849 days ago, the information mentioned may be changed or developed.
    import pygeoip
    gi = pygeoip.GeoIP('GeoLiteCity.dat')
    respOnse= gi.record_by_addr(ip)
    我正常导入库,路径也正确,想要用 Python 的 pygeoip 库通过 ip 获取经纬,然后给百度地图,在页面显示,结果在形成对象这儿卡住了
    各位大佬,帮吗看一下是啥情况?

    分割线

    File "/usr/local/lib/python2.7/site-packages/pygeoip/__init__.py", line 118, in __init__
    self._fp = codecs.open(filename, 'rb', ENCODING)
    File "/usr/local/lib/python2.7/codecs.py", line 896, in open
    ------------if mode[:1] not in set('rwa'):
    --------------mode = 'r' + mode
    Open an interactive python shell in this frame if 'b' not in mode:
    ------------# Force opening of the file in binary mode
    ------------mode = mode + 'b'
    ----file = __builtin__.open(filename, mode, buffering) # 报这个错误!!!
    ----if encoding is None:
    --------return file
    ----info = lookup(encoding)
    ----srw = StreamReaderWriter(file, info.streamreader, info.streamwriter, errors)
    ----# Add attributes to simplify introspection
    IOError: [Errno 2] No such file or directory: 'GeoLiteCity.dat'
    6 replies    2018-07-27 09:48:56 +08:00
    xiexingjia
        1
    xiexingjia  
       Jul 26, 2018
    No such file or directory: 'GeoLiteCity.dat'
    Yycreater
        2
    Yycreater  
    OP
       Jul 26, 2018
    文件我直接放在同级目录下了,文件路径没问题,刚刚在项目外面试了一下{'city': u'Shenzhen', 'region_code': u'30', 'area_code': 0, 'time_zone': 'Asia/Chongqing', 'dma_code': 0, 'metro_code': None, 'country_code3': 'CHN', 'latitude': 22.533299999999997, 'postal_code': None, 'longitude': 114.13330000000002, 'country_code': 'CN', 'country_name': 'China', 'continent': 'AS'}
    很 ok !项目内就是不行。。。。
    KeatingSmith
        3
    KeatingSmith  
       Jul 26, 2018 via iPhone
    使用绝对路径吧。

    有可能你的 Python 运行路径与文件路径不一致,而你又使用的是相对路径
    Yycreater
        4
    Yycreater  
    OP
       Jul 26, 2018
    试了,还是报那个错误~~~
    lieh222
        5
    lieh222  
       Jul 27, 2018   1
    print(os.getcwd())
    self._fp = codecs.open(filename, 'rb', ENCODING)
    您瞧瞧打印的当前路径对不对
    Yycreater
        6
    Yycreater  
    OP
       Jul 27, 2018
    @lieh222 托您的福,用 print os.path.realpath(__file__)
    print '*' * 50 方法调好了路径
    About     Help     Advertise     Blog     API     FAQ     Solana     6094 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 47ms UTC 06:25 PVG 14:25 LAX 23:25 JFK 02:25
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86