找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 4807|回复: 6

如何将Python脚本转成EXE文件

3

主题

8

帖子

8

积分

贫民

积分
8
zjr 发表于 2016-11-16 14:50:37 | 显示全部楼层 |阅读模式
本帖最后由 zjr 于 2016-11-16 15:02 编辑

如何将Python写的.py脚本转成EXE文件,或者如何脱离Python环境运行。
  1. #-*- coding: UTF-8 -*-
  2. print "AD账号=姓名首拼+工号,如:abc12345"
  3. while True:
  4.     AD=raw_input("请输入AD账号:")
  5.     if len(AD) == 0:
  6.             continue
  7.     else:
  8.             break
  9. str=''';Automatically generated PRF file from the Microsoft Office Customization and Installation Wizard

  10. ; **************************************************************
  11. ; Section 1 - Profile Defaults
  12. ; **************************************************************

  13. [General]
  14. Custom=1
  15. ProfileName=outlookanywhere
  16. DefaultProfile=Yes
  17. OverwriteProfile=Yes
  18. ModifyDefaultProfileIfPresent=false
  19. DefaultStore=Service1

  20. ; **************************************************************
  21. ; Section 2 - Services in Profile
  22. ; **************************************************************

  23. [Service List]
  24. ;ServiceX=Microsoft Outlook Client
  25. ServiceEGS1=Exchange Global Section
  26. Service1=Microsoft Exchange Server

  27. ;***************************************************************
  28. ; Section 3 - List of internet accounts
  29. ;***************************************************************

  30. [Internet Account List]

  31. ;***************************************************************
  32. ; Section 4 - Default values for each service.
  33. ;***************************************************************

  34. ;[ServiceX]
  35. ;FormDirectoryPage=
  36. ;-- The URL of Exchange Web Services Form Directory page used to create Web forms.
  37. ;WebServicesLocation=
  38. ;-- The URL of Exchange Web Services page used to display unknown forms.
  39. ;ComposeWithWebServices=
  40. ;-- Set to true to use Exchange Web Services to compose forms.
  41. ;PromptWhenUsingWebServices=
  42. ;-- Set to true to use Exchange Web Services to display unknown forms.
  43. ;OpenWithWebServices=
  44. ;-- Set to true to prompt user before opening unknown forms when using Exchange Web Services.


  45. [ServiceEGS1]
  46. MailboxName=zjr16055@ly.com
  47. HomeServer=excas.tcent.cn
  48. AccountName=tcent\zjr16055
  49. ConfigFlags=0x00000000
  50. RPCoverHTTPflags=0x0027
  51. RPCProxyServer=mail.ly.com
  52. RPCProxyPrincipalName=msstd:mail.ly.com
  53. RPCProxyAuthScheme=0x0001

  54. [Service1]
  55. OverwriteExistingService=No
  56. UniqueService=No
  57. MailboxName=zjr16055@ly.com
  58. HomeServer=excas.tcent.cn
  59. DefaultAccount=TRUE

  60. ;***************************************************************
  61. ; Section 5 - Values for each internet account.
  62. ;***************************************************************

  63. ;***************************************************************
  64. ; Section 6 - Mapping for profile properties
  65. ;***************************************************************

  66. [Microsoft Exchange Server]
  67. ServiceName=MSEMS
  68. MDBGUID=5494A1C0297F101BA58708002B2A2517
  69. MailboxName=PT_STRING8,0x6607
  70. HomeServer=PT_STRING8,0x6608
  71. OfflineAddressBookPath=PT_STRING8,0x660E
  72. OfflineFolderPathAndFilename=PT_STRING8,0x6610

  73. [Exchange Global Section]
  74. SectionGUID=13dbb0c8aa05101a9bb000aa002fc45a
  75. MailboxName=PT_STRING8,0x6607
  76. HomeServer=PT_STRING8,0x6608
  77. ConfigFlags=PT_LONG,0x6601
  78. RPCoverHTTPflags=PT_LONG,0x6623
  79. RPCProxyServer=PT_UNICODE,0x6622
  80. RPCProxyPrincipalName=PT_UNICODE,0x6625
  81. RPCProxyAuthScheme=PT_LONG,0x6627
  82. AccountName=PT_UNICODE,0x6620

  83. [Microsoft Mail]
  84. ServiceName=MSFS
  85. ServerPath=PT_STRING8,0x6600
  86. Mailbox=PT_STRING8,0x6601
  87. Password=PT_STRING8,0x67f0
  88. RememberPassword=PT_BOOLEAN,0x6606
  89. ConnectionType=PT_LONG,0x6603
  90. UseSessionLog=PT_BOOLEAN,0x6604
  91. SessionLogPath=PT_STRING8,0x6605
  92. EnableUpload=PT_BOOLEAN,0x6620
  93. EnableDownload=PT_BOOLEAN,0x6621
  94. UploadMask=PT_LONG,0x6622
  95. NetBiosNotification=PT_BOOLEAN,0x6623
  96. NewMailPollInterval=PT_STRING8,0x6624
  97. DisplayGalOnly=PT_BOOLEAN,0x6625
  98. UseHeadersOnLAN=PT_BOOLEAN,0x6630
  99. UseLocalAdressBookOnLAN=PT_BOOLEAN,0x6631
  100. UseExternalToHelpDeliverOnLAN=PT_BOOLEAN,0x6632
  101. UseHeadersOnRAS=PT_BOOLEAN,0x6640
  102. UseLocalAdressBookOnRAS=PT_BOOLEAN,0x6641
  103. UseExternalToHelpDeliverOnRAS=PT_BOOLEAN,0x6639
  104. ConnectOnStartup=PT_BOOLEAN,0x6642
  105. DisconnectAfterRetrieveHeaders=PT_BOOLEAN,0x6643
  106. DisconnectAfterRetrieveMail=PT_BOOLEAN,0x6644
  107. DisconnectOnExit=PT_BOOLEAN,0x6645
  108. DefaultDialupConnectionName=PT_STRING8,0x6646
  109. DialupRetryCount=PT_STRING8,0x6648
  110. DialupRetryDelay=PT_STRING8,0x6649

  111. [Personal Folders]
  112. ServiceName=MSPST MS
  113. Name=PT_STRING8,0x3001
  114. PathAndFilenameToPersonalFolders=PT_STRING8,0x6700
  115. RememberPassword=PT_BOOLEAN,0x6701
  116. EncryptionType=PT_LONG,0x6702
  117. Password=PT_STRING8,0x6703

  118. [Unicode Personal Folders]
  119. ServiceName=MSUPST MS
  120. Name=PT_UNICODE,0x3001
  121. PathAndFilenameToPersonalFolders=PT_STRING8,0x6700
  122. RememberPassword=PT_BOOLEAN,0x6701
  123. EncryptionType=PT_LONG,0x6702
  124. Password=PT_STRING8,0x6703

  125. [Outlook Address Book]
  126. ServiceName=CONTAB

  127. [LDAP Directory]
  128. ServiceName=EMABLT
  129. ServerName=PT_STRING8,0x6600
  130. UserName=PT_STRING8,0x6602
  131. UseSSL=PT_BOOLEAN,0x6613
  132. UseSPA=PT_BOOLEAN,0x6615
  133. EnableBrowsing=PT_BOOLEAN,0x6622
  134. DisplayName=PT_STRING8,0x3001
  135. ConnectionPort=PT_STRING8,0x6601
  136. SearchTimeout=PT_STRING8,0x6607
  137. MaxEntriesReturned=PT_STRING8,0x6608
  138. SearchBase=PT_STRING8,0x6603
  139. CheckNames=PT_STRING8,0x6624
  140. DefaultSearch=PT_LONG,0x6623

  141. [Microsoft Outlook Client]
  142. SectionGUID=0a0d020000000000c000000000000046
  143. FormDirectoryPage=PT_STRING8,0x0270
  144. WebServicesLocation=PT_STRING8,0x0271
  145. ComposeWithWebServices=PT_BOOLEAN,0x0272
  146. PromptWhenUsingWebServices=PT_BOOLEAN,0x0273
  147. OpenWithWebServices=PT_BOOLEAN,0x0274
  148. CachedExchangeMode=PT_LONG,0x041f
  149. CachedExchangeSlowDetect=PT_BOOLEAN,0x0420

  150. [Personal Address Book]
  151. ServiceName=MSPST AB
  152. NameOfPAB=PT_STRING8,0x001e3001
  153. PathAndFilename=PT_STRING8,0x001e6600
  154. ShowNamesBy=PT_LONG,0x00036601

  155. ; ************************************************************************
  156. ; Section 7 - Mapping for internet account properties.  DO NOT MODIFY.
  157. ; ************************************************************************

  158. [I_Mail]
  159. AccountType=POP3
  160. ;--- POP3 Account Settings ---
  161. AccountName=PT_UNICODE,0x0002
  162. DisplayName=PT_UNICODE,0x000B
  163. EmailAddress=PT_UNICODE,0x000C
  164. ;--- POP3 Account Settings ---
  165. POP3Server=PT_UNICODE,0x0100
  166. POP3UserName=PT_UNICODE,0x0101
  167. POP3UseSPA=PT_LONG,0x0108
  168. Organization=PT_UNICODE,0x0107
  169. ReplyEmailAddress=PT_UNICODE,0x0103
  170. POP3Port=PT_LONG,0x0104
  171. POP3UseSSL=PT_LONG,0x0105
  172. ; --- SMTP Account Settings ---
  173. SMTPServer=PT_UNICODE,0x0200
  174. SMTPUseAuth=PT_LONG,0x0203
  175. SMTPAuthMethod=PT_LONG,0x0208
  176. SMTPUserName=PT_UNICODE,0x0204
  177. SMTPUseSPA=PT_LONG,0x0207
  178. ConnectionType=PT_LONG,0x000F
  179. ConnectionOID=PT_UNICODE,0x0010
  180. SMTPPort=PT_LONG,0x0201
  181. SMTPSecureConnection=PT_LONG,0x020A
  182. ServerTimeOut=PT_LONG,0x0209
  183. LeaveOnServer=PT_LONG,0x1000

  184. [IMAP_I_Mail]
  185. AccountType=IMAP
  186. ;--- IMAP Account Settings ---
  187. AccountName=PT_UNICODE,0x0002
  188. DisplayName=PT_UNICODE,0x000B
  189. EmailAddress=PT_UNICODE,0x000C
  190. ;--- IMAP Account Settings ---
  191. IMAPServer=PT_UNICODE,0x0100
  192. IMAPUserName=PT_UNICODE,0x0101
  193. IMAPUseSPA=PT_LONG,0x0108
  194. Organization=PT_UNICODE,0x0107
  195. ReplyEmailAddress=PT_UNICODE,0x0103
  196. IMAPPort=PT_LONG,0x0104
  197. IMAPUseSSL=PT_LONG,0x0105
  198. ; --- SMTP Account Settings ---
  199. SMTPServer=PT_UNICODE,0x0200
  200. SMTPUseAuth=PT_LONG,0x0203
  201. SMTPAuthMethod=PT_LONG,0x0208
  202. SMTPUserName=PT_UNICODE,0x0204
  203. SMTPUseSPA=PT_LONG,0x0207
  204. ConnectionType=PT_LONG,0x000F
  205. ConnectionOID=PT_UNICODE,0x0010
  206. SMTPPort=PT_LONG,0x0201
  207. SMTPSecureConnection=PT_LONG,0x020A
  208. ServerTimeOut=PT_LONG,0x0209
  209. CheckNewImap=PT_LONG,0x1100
  210. RootFolder=PT_UNICODE,0x1101
  211. Account=PT_UNICODE,0x0002
  212. HttpServer=PT_UNICODE,0x0100
  213. UserName=PT_UNICODE,0x0101
  214. Organization=PT_UNICODE,0x0107
  215. UseSPA=PT_LONG,0x0108
  216. TimeOut=PT_LONG,0x0209
  217. Reply=PT_UNICODE,0x0103
  218. EmailAddress=PT_UNICODE,0x000C
  219. FullName=PT_UNICODE,0x000B
  220. Connection Type=PT_LONG,0x000F
  221. ConnectOID=PT_UNICODE,0x0010
  222. '''
  223. prf=file("d:\outlook.PRF",'w')
  224. prf.write(str.replace('zjr16055',AD))
  225. prf.close()

  226. cmd='''cd /d C:\Program Files\Microsoft Office\office14
  227. outlook.exe /importprf d:\outlook.prf
  228. '''
  229. bat=file("d:\outlook.bat",'w')
  230. bat.write(cmd)
  231. bat.close()
  232. os.system("d:\outlook.bat")
复制代码


回复

使用道具 举报

1

主题

8

帖子

9

积分

贫民

积分
9
Min-Coco 发表于 2016-11-26 21:19:22 | 显示全部楼层
厉害了,我的天!
回复 支持 反对

使用道具 举报

3

主题

278

帖子

278

积分

侠客

积分
278

热心会员

uitb 发表于 2016-11-27 17:29:05 | 显示全部楼层
好像有个什么模块可以做到,百度一下啦
回复 支持 反对

使用道具 举报

0

主题

8

帖子

8

积分

贫民

积分
8
zx0308 发表于 2016-12-27 16:50:49 | 显示全部楼层
可以用py2exe完成
代码如下:
from distutils.core import setup
import py2exe

setup(windows=[u'路径\文件名.py'])
回复 支持 反对

使用道具 举报

0

主题

8

帖子

8

积分

贫民

积分
8
zx0308 发表于 2016-12-27 16:54:33 | 显示全部楼层
  1. from distutils.core import setup
  2. import py2exe

  3. setup(windows=[u'C:\\python34\\路径\文件名.py'])
复制代码
回复 支持 反对

使用道具 举报

0

主题

8

帖子

8

积分

贫民

积分
8
zx0308 发表于 2017-1-8 14:47:00 | 显示全部楼层
如果这个文件名为setup.py则在命令行里用路径\setup.py py2exe执行
回复 支持 反对

使用道具 举报

0

主题

2

帖子

2

积分

贫民

积分
2
lss89225 发表于 2017-2-9 17:39:05 | 显示全部楼层
使用PyInstaller模块
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表