1
pyw
文件格式主要用于运行纯 GUI(图形用户界面)程序的 Python 脚本。这些纯 GUI 程序的用户不需要看到类似 CMD 命令的黑色 shell 控制台窗口。当运行 .pyw
文件时,所有标准输出(stdout
)和标准错误输出(stderr
)都无效,而原始标准输入(stdin
)的读取只会得到 EOF(文件结束符)。你可以通过双击直接运行 .pyw
文件,系统会调用 pythonw.exe
来运行。如果需要将相关信息输出,可以使用以下命令:
pythonw \\path\\xxx.pyw 1> \\path\\stdout.txt 2> \\path\\stderr.txt
其中:
1
代表标准输出,将标准输出重定向到stdout.txt
中。2
代表错误输出,将错误输出重定向到stderr.txt
中。
在 Linux 环境中,所有文件不区分扩展名,而是根据内容使用相应的程序运行,因此 .pyw
后缀和 .pyc
后缀没有区别².
源: 与 Copilot 的对话, 2024/6/20
(1) PYW 文件格式 - Python GUI 源文件 - File Format Docs. https://bing.com/search?q=pyw文件格式.
(2) py,pyc,pyw文件的区别和使用 - 倥偬时光 - 博客园. https://www.cnblogs.com/cwp-bg/p/8508847.html.
(3) Python 常见文件格式 .py .pyc .pyw .pyo .pyd_python文件 .... https://blog.csdn.net/cmzhuang/article/details/80109603.
(4) 【python】Python 常见文件格式 .py .pyc .pyw .pyo .pyd简介. https://blog.csdn.net/All_In_gzx_cc/article/details/126135653.
(5) PYW 文件格式 - Python GUI 源文件 - File Format Docs. https://docs.fileformat.com/zh/programming/pyw/.
2
python服务在windows server上的开机启动和托盘后台运行
将python的主入口程序的后缀,从.py改为.pyw,创建快捷方式,放在
C:\Users\用户名\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup文件夹,即可实现开机自启
https://blog.51cto.com/u_16055028/11187144
https://blog.csdn.net/xuqingda/article/details/136373127
3
在 Windows 操作系统中,你可以使用以下几种方法将 Python 脚本设置为开机自启动项:
- 通过注册表编辑器添加启动项:
- 打开注册表编辑器(按下
Win + R
,输入regedit
并点击“确定”)。 - 在注册表编辑器中,找到路径
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
。 - 右键点击
Run
文件夹,选择“新建” -> “字符串值”。 - 命名新建的字符串值,并在数据中键入需要自启动的程序或脚本的绝对路径,例如
"C:\Program Files\Python36\python.exe D:\project\test.py"
。 - 重启 Windows 系统,即可实现 Python 脚本开机自启动⁶.
- 将文件添加到 Windows 启动文件夹中:
- 按下
Win + R
键打开“运行”对话框。 - 输入
shell:startup
并点击“确定”。 - 将要启动的 Python 文件复制到打开的文件夹中。
- 确保 Python 文件具有可执行权限。
- 现在,每次 Windows 启动时,你的 Python 文件都会自动运行⁷.
如果你使用的是 CentOS 系统,你可以按照以下步骤将 Python 脚本设置为开机启动项:
- 创建服务文件:
- 假设你需要开机启动的脚本为
test.py
,其所在的绝对路径为/root/python/test.py
。 - 创建
yourServer.service
文件,并放入/etc/systemd/system/
目录下。 yourServer.service
的内容如下:
[Unit]
Description=imageclassification
After=multi-user.target
[Service]
StartLimitInterval=5
StartLimitBurst=10
ExecStart=/root/anaconda3/bin/python /root/python/test.py
WorkingDirectory=/root/python/
Restart=always
[Install]
WantedBy=multi-user.target
- 需要注意的是,
ExecStart
后的 Python 和程序所在路径必须是绝对路径,此处 Python 的路径也可以是你自己定义的 Python 路径,与系统 Python 路径隔离,方便移植和部署。
- 创建启动脚本:
- 在
test.py
的同路径下创建yourServer_start.sh
文件。 yourServer_start.sh
的内容如下:
cp yourServer.service /etc/systemd/system # 将服务放在 /etc/systemd/system 目录下
chmod 644 /etc/systemd/system/yourServer.service # 配置权限
systemctl daemon-reload # 重载服务列表
systemctl enable yourServer.service # 设置开机自启动
systemctl start yourServer.service # 启动服务
- 使用以下命令查看服务是否正常开启:
systemctl start yourServer.service
。 - 使用以下命令查看服务是否正常停止:
systemctl stop yourServer.service
。 - 根据实际需要,使用以下命令将服务设为开机自启动:
systemctl enable yourServer.service
。
源: 与 Copilot 的对话, 2024/6/20
(1) Windows系统配置python脚本开机启动的3种方法分享 .... https://pythonjishu.com/dbojagazqswkymb/.
(2) Python 如何在Windows启动时启动一个Python文件 - 极客教程. https://geek-docs.com/python/python-ask-answer/484_python_how_to_start_a_python_file_while_windows_starts.html.
(3) 将Python脚本加入开机启动项(WIN10、CentOS) - CSDN博客. https://blog.csdn.net/qq_41699621/article/details/110630446.
(4) Python 如何在Windows启动时启动一个Python文件 - 极客教程. https://bing.com/search?q=pyw文件设为开机自启动.
(5) python 设置开机自动启动 .py 文件 - CSDN博客. https://blog.csdn.net/weixin_44493841/article/details/107229228.
(6) python 开机 定时启动 - LmtMe - 博客园. https://www.cnblogs.com/LMTlmt/p/11389730.html.
(7) Windows开机自动运行.py文件_开机运行py文件-CSDN博客. https://blog.csdn.net/include_6666/article/details/89512958.
4
tortoiseGit 步骤
来到子项目文件夹 右键 commit
message,All, commit,push
注意:
点all, 点push