Python编写一个简单的百度搜索应用

由于天气因素,无法外出,在家闲来无事,使用Python编写一个简单的百度搜索应用。

功能:打开默认浏览器,使用百度进行搜索

Python:2.7.13

第三方库:pyinstaller(打包软件)

工具:upx-3.95-win32(压缩exe大小)

通过pip安装pyinstaller3.3.1版本:

pyinstaller 安装命令:pip install pyinstaller==3.3.1

实际中pyinstaller 3.4遇到了一个异常问题,改用了3.3.1版本:

Traceback (most recent call last):
  File "C:\Python27\Scripts\pyinstaller-script.py", line 11, in <module>
    load_entry_point('PyInstaller==3.4', 'console_scripts', 'pyinstaller')()
  File "c:\python27\lib\site-packages\pkg_resources\__init__.py", line 480, in l
oad_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "c:\python27\lib\site-packages\pkg_resources\__init__.py", line 2693, in
load_entry_point
    return ep.load()
  File "c:\python27\lib\site-packages\pkg_resources\__init__.py", line 2324, in
load
    return self.resolve()
  File "c:\python27\lib\site-packages\pkg_resources\__init__.py", line 2330, in
resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "c:\python27\lib\site-packages\PyInstaller\__init__.py", line 72, in <mod
ule>
    DEFAULT_SPECPATH = compat.getcwd()
  File "c:\python27\lib\site-packages\PyInstaller\compat.py", line 613, in getcw
d
    cwd = win32api.GetShortPathName(cwd)
AttributeError: 'module' object has no attribute 'GetShortPathName'

pyinstaller具体使用方法可以参考 胖玻璃球就一个 的博客:

https://blog.csdn.net/xinyingzai/article/details/80282856

upx下载链接:

https://github.com/upx/upx/releases/tag/v3.95

应用代码如下:

#coding=utf-8
import webbrowser,sys
if sys.getdefaultencoding() != 'gbk':
	reload(sys)
	sys.setdefaultencoding('gbk')
print "输入:'#q'or'#Q',退出工具".decode('utf-8')   
while True:
    try:
		rst = raw_input(">>>#:")
		if rst in ["#q","#Q"]:
			break
		print "open baidu search:{}".format(rst)
		webbrowser.open(url=u"https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=0&rsv_idx=1&tn=baidu&wd={}".format(rst.decode('gbk')))
    except:
        pass

打包命令:pyinstaller -F -i serch.ico --upx upx-3.95-win32 BaiduSearch.py

参数说明:

-i serch.ico 软件图标为:serch.ico

--upx upx-3.95-win32 使用upx压缩软件大小

BaiduSearch.py 要打包的python文件

打包过程中出现了两个问题:

1.

Traceback (most recent call last):
  File "C:\Python27\Scripts\pyinstaller-script.py", line 11, in <module>
    load_entry_point('PyInstaller==3.3.1', 'console_scripts', 'pyinstaller')()
  File "c:\python27\lib\site-packages\PyInstaller\__main__.py", line 94, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "c:\python27\lib\site-packages\PyInstaller\__main__.py", line 46, in run_
build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "c:\python27\lib\site-packages\PyInstaller\building\build_main.py", line
791, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'
))
  File "c:\python27\lib\site-packages\PyInstaller\building\build_main.py", line
737, in build
    exec(text, spec_namespace)
  File "<string>", line 29, in <module>
  File "c:\python27\lib\site-packages\PyInstaller\building\api.py", line 397, in
 __init__
    self.console, self.uac_admin, self.uac_uiaccess)
  File "c:\python27\lib\site-packages\PyInstaller\utils\win32\winmanifest.py", l
ine 1038, in create_manifest
    manifest = ManifestFromXMLFile(filename)
  File "c:\python27\lib\site-packages\PyInstaller\utils\win32\winmanifest.py", l
ine 999, in ManifestFromXMLFile
    manifest.parse(filename_or_file)
  File "c:\python27\lib\site-packages\PyInstaller\utils\win32\winmanifest.py", l
ine 753, in parse
    self.load_dom(domtree, False)
  File "c:\python27\lib\site-packages\PyInstaller\utils\win32\winmanifest.py", l
ine 721, in load_dom
    (self.filename, manifest.name))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd7 in position 9: ordinal
not in range(128)

解决方法参考:https://blog.csdn.net/lusongno1/article/details/62891860?utm_source=blogxgwz1

2.

Traceback (most recent call last):
  File "C:\Python27\Scripts\pyinstaller-script.py", line 11, in <module>
    load_entry_point('PyInstaller==3.3.1', 'console_scripts', 'pyinstaller')()
  File "c:\python27\lib\site-packages\PyInstaller\__main__.py", line 94, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "c:\python27\lib\site-packages\PyInstaller\__main__.py", line 46, in run_
build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "c:\python27\lib\site-packages\PyInstaller\building\build_main.py", line
791, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'
))
  File "c:\python27\lib\site-packages\PyInstaller\building\build_main.py", line
737, in build
    exec(text, spec_namespace)
  File "<string>", line 29, in <module>
  File "c:\python27\lib\site-packages\PyInstaller\building\api.py", line 411, in
 __init__
    strip_binaries=self.strip, upx_binaries=self.upx,
  File "c:\python27\lib\site-packages\PyInstaller\building\api.py", line 196, in
 __init__
    self.__postinit__()
  File "c:\python27\lib\site-packages\PyInstaller\building\datastruct.py", line
161, in __postinit__
    self.assemble()
  File "c:\python27\lib\site-packages\PyInstaller\building\api.py", line 259, in
 assemble
    dist_nm=inm)
  File "c:\python27\lib\site-packages\PyInstaller\building\utils.py", line 198,
in checkCache
    cachedfile = os.path.join(cachedir, basenm)
  File "c:\python27\lib\ntpath.py", line 85, in join
    result_path = result_path + p_path
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd7 in position 7: ordinal
not in range(128)

解决方法参考:https://blog.csdn.net/lxl743p/article/details/78708088?utm_source=blogkpcl7

工具使用截图:

 

已经完成的工具与图标附件:https://download.csdn.net/download/zichehantz/10828662

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试