1.pip源
https://pypi.tuna.tsinghua.edu.cn/simple/
https://pypi.doubanio.com/simple/
2.手动安装库
python setup.py install
3.生成requirement.txt
pipreqs ./ --coding=gbk(有时为utf-8)
4.打包压缩
python内置包zipfile、tarfile
import zipfile,os
def zipall(startdir,out_file):
z = zipfile.ZipFile(out_file, 'w', zipfile.ZIP_DEFLATED)
for dirpath, dirnames, filenames in os.walk(startdir):
for filename in filenames:
z.write(os.path.join(dirpath, filename))
z.close()
print("complish")
if __name__=="__main__":
#需要压缩的文件夹,输出文件
zipall("DB_Net","DBnet.zip")
5.按操作系统切分路径
“fgdsg/fgd/fgd/gd”.split(os.sep)
6.虚拟环境
创建:python -m venv dirname
windows:
使用:dirname\scripts\activate.bat
退出:dirname\scripts\deactivate.bat
linux:
使用:dirname/bin#source activate
退出:deactivate
删除环境:删除目录
7.禁用runtimewarning
import warnings
warnings.filterwarnings(“ignore”)
8.视频裁剪
import sys
from moviepy.editor import *
def clip(infile,outfile,start,end):
video_tmp=VideoFileClip(infile).subclip(t_start=start,t_end=end) #(hour,minute,second)
video_tmp.write_videofile(outfile)
if __name__=="__main__":
if len(sys.argv)==5:
clip(sys.argv[1],sys.argv[2],sys.argv[3],sys.argv[4])
print("clip complish!")
else:
print("usage: python movie_clip.py infile_name outfile_name start_time,end_time")