代码打包为.exe软件(python)

打开控制面板,输入python代码文件的硬盘目录,如:E:
![在这里插入图片描述](https://img-blog.csdnimg.cn/2020092922115491.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2NvbmZ1c2luZ2dnZw==,size_16,color_FFFFFF,t_70#pic_center我以自己制作的某小说爬取代码为例,为了简单,文件名为:1.py。

import requests
#import os
#import time
import re
from bs4 import BeautifulSoup
di=[]
dx=[]
url="http://www.paoshu8.com/1_1010/"
res=requests.get(url)
res.raise_for_status()
res.encoding=res.apparent_encoding
soup=BeautifulSoup(res.text,"html.parser")
d=soup.find_all("dd")
for m in d:
    m=m.find_all("a")
    dx.append(m)
#print(dx)
sum=0
for i in dx:
    i=i[0]
    #print(i)
    i= i["href"]
    if "/1_1010" in i:
        di.append(i)
    else:
        continue
    sum=sum+1
a=eval(input("输入章节数:"))+30
url1="http://www.paoshu8.com/"+di[a]
b=0
while 1:
 j=0
 if b==0:
   res1=requests.get(url1)
   res1.raise_for_status()
   res1.encoding=res1.apparent_encoding
   soup=BeautifulSoup(res1.text,"html.parser")
   neinou=soup.find_all("p")
   for i in neinou:
     print(i)
   b=1
 m=input("按a或者A表示上一章,d或者D为下一章:")
 if m in ["a","A"]:
   if a==31:
     continue
   else:
      a=a-1
      b=0
   url1="http://www.paoshu8.com/"+di[a]
 if m in ["d","D"]:
   if a==sum:
     continue
   else:
      a=a+1
      b=0
   url1="http://www.paoshu8.com/"+di[a]

打包程序(含黑框)----------pyinstaller -F xxx.py。
打包程序(摆脱控制台黑框)
(1)把你写好的python程序文件的扩展名改为.pyw就会调用pythonw.exe执行不带控制台的程序。如何想要别人也机器也能运行你的程序可以用py2exe软件。
(2)用pyinstaller打包成.exe时添加-w参数。即可摆脱控制台黑框。
比如:pyinstaller xxx.py -w -F。

在此我以pyinstaller -F xxx.py为例。
在这里插入图片描述
在这里插入图片描述出现successfully则表明成功了。

最后,你便可以在***.py文件同目录下看到dist文件夹。
在这里插入图片描述

在这里插入图片描述

  • 4
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值