准备过程
- 安装:PyInstaller
1.解压PyInstaller-3.6.tar.gz放到python3的目录下,
2.cmd切换到python3的PyInstaller-3.6下,
在当前目录下,cmd输入
python setup.py install
出现successful安装完成
转换过程
-
脚本转exe小程序:
1.cmd切换到对应的python脚本下,
输入
pyinstaller -F vehicle.py
常用参数说明:
–icon=图标路径
-F 打包成一个exe文件
-w 使用窗口,无控制台
-c 使用控制台,无窗口
-D 创建一个目录,里面包含exe以及其他一些依赖性文件
pyinstaller -h 来查看参数
回车后,代码迅速操作,直到操作结束。
出现completed successfully转换成功
- 打开文件夹查看:
双击vehicle.exe打开
-
2更换小程序的图标:
在当前page这个目录下输入
pyinstaller -F --icon=favicon.ico vehicle.py
注:普通的图片转换成ico格式链接,例如http://www.ico51.cn/
普通图标
- 我的小脚本,打开exe包,只需要输入起点和终点,就能打印出来高德地图上的途经点
import re
import requests
def Route_distance_all(start_point, terminal_point):
url = "https://restapi.amap.com/v3/direction/driving"
par = "key=在高德上注册的key&origin={}&destination={}&originid=&destinationid=&extensions=base&strategy=0&waypoints=&avoidpolygons=&avoidroad=".format(
start_point, terminal_point)
response = requests.get(url, par)
content = str(response.json()["route"]["paths"]).replace("\n", "").replace("\r", "").replace("\t", "")
polyline = str(re.findall(r"'polyline': '(.*?)'", content)).replace('"', '').replace("', '", ";").split(";")[2:-2]
print(";".join(polyline))
# 116.281469,40.048146东软
# 116.33031,40.083789云趣园
# Route_distance_all( "116.281469,40.048146","116.33031,40.083789")
if __name__ == "__main__":
while True:
start_point = input("请输入起始位置(不输入则起点自动默认东软:116.281469,40.048146)")or "116.281469,40.048146"
terminal_point = input("请输入目的地位置(不输入则目的地自动默认云趣园:116.33031,40.083789)")or "116.33031,40.083789"
route = Route_distance_all(start_point, terminal_point)
input("please input any key to exit!") #解决exe打开一闪而过的问题
报错:WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
官网上下载与系统相应的最新版本geckodriver,解压放到Python的安装目录下,如果是放在其它目录下需要自己再配一下环境变量
https://github.com/mozilla/geckodriver/releases