分类: Linux

Debian和 Ubuntu下将Python程序打包成.deb安装包

查看python版本

it0@it0-pc:~/桌面/tests/testdeb$ python3 -V
Python 3.8.10

查看pip版本

it0@it0-pc:~/桌面/tests/testdeb$ pip3 -V
pip 24.1.2 from /usr/local/lib/python3.8/dist-packages/pip (python 3.8)

将工程打包生成一个可执行文件

注意一定要保证python程序在电脑上可以正常运行!!!!!!!
该安装第三方库的安装库,该安装扩展的安装扩展!!!!!!!

python3 main.py

当前项目目录结构

.
├── config
├── DB
├── horizontalSliderUI.py
├── icons
├── main.py
├── ui
└── utils

安装pyinstaller

pip3 install pyinstaller

检查pyinstaller安装成功

pyinstaller -v

在python代码项目目录执行以下命令

pyinstaller -F -w main.py
# 可以通过pyinstaller --help查看帮助

此时项目结构 (产生了build、dist、main.spec)文件和文件夹

.
├── build
├── config
├── DB
├── dist
├── horizontalSliderUI.py
├── icons
├── main.py
├── main.spec
├── ui
└── utils

dist目录中的main文件就是编译好的二进制文件。
此时从其他地方新建目录testa把二进制移动到该目录
此时testa目录结构为:

.
└── main

把程序的依赖配置目录啥的都放到testa目录下(此处为testa示例 根据自己实际情况来)

.
├── DB
│   ├── log
│   │   └── log.txt
│   └── user_DB.db
└── main

此时终端到testa目录下执行./main文件测试程序是否可以正常启动,如有问题就看终端上的报错,没有问题则进行下一步。

把可执行程序和依赖文件打包成.deb文件

在其他位置新建makedeb目录,然后按照以下结构创建目录结构,以下是我makedeb目录下的结构

├── DEBIAN
└── usr
    ├── lib
    └── share
        ├── applications
        └── icons

将testa目录直接移动到lib目录下

├── DEBIAN
└── usr
    ├── lib
    │   └── testa
    │       ├── DB
    │       │   ├── log
    │       │   │   └── log.txt
    │       │   └── user_DB.db
    │       └── main
    └── share
        ├── applications
        └── icons

到DEBIAN目录新增control文件,内容如下(自行百度含义):

Package: debpacktest
Version: 1.0.0
Architecture: arm64
Maintainer: gao
Description: just a test

在/usr/share/applications下制作桌面图标 testa.desktop文件

[Desktop Entry]
Name=debpacktest
Comment=An example
Exec=/usr/lib/testa/m/main #可执行文件路径
Icon=/usr/share/icons/icc.ico #图标路径
Terminal=false #是否运行同时打开终端
Type=Application
X-Ubuntu-Touch=true
Categories=Development

为这个文件添加可执行权限

chmod +x testa.desktop

在/usr/share/icons/文件夹下放icc.ico图标(图标名自定义跟上边配置呼应)
此时makedeb的目录结构如下:

├── DEBIAN
│   └── control
└── usr
    ├── lib
    │   └── testa
    │       ├── DB
    │       │   ├── log
    │       │   │   └── log.txt
    │       │   └── user_DB.db
    │       └── main
    └── share
        ├── applications
        │   └── testa.desktop
        └── icons
            └── icc.ico

到这里,一个基本的deb软件包就大功告成了。
我们返回到makedeb的上级目录。我们执行

sudo dpkg -b makedeb makedeb_1.0.0_arm64.deb

包的命名要符合规范,我这里是随便打的。
检验的话,可以输入(安装deb包)

sudo dpkg -i makedeb_1.0.0_arm64.deb

我在应用列表里看到了我的程序
如果要卸载,请执行

sudo dpkg -r makedeb

参考链接
https://blog.csdn.net/u013541325/article/details/114954959
https://blog.csdn.net/qq_43790749/article/details/118027929

CentOS 7.9 更新CURL到最新稳定版的方法

在安装swoole5.1版本的时候遇到centos7.9 curl版本过低问题,导致无法安装swoole扩展
下边是详细解决办法

添加一个新的repo

vim /etc/yum.repos.d/city-fan.repo

然后在里面添加如下内容:

Centos6 编辑为如下:

[CityFanforCurl]
name=City Fan Repo
baseurl=http://www.city-fan.org/ftp/contrib/yum-repo/rhel6/x86_64/
enabled=0
gpgcheck=0

Centos7 编辑为如下:

[CityFanforCurl]
name=City Fan Repo
baseurl=http://www.city-fan.org/ftp/contrib/yum-repo/rhel7/x86_64/
enabled=0
gpgcheck=0

更新 cURL 直接使用如下命令进行更新:

yum update curl --enablerepo=CityFanforCurl -y

cURL将会更新到一个最新的稳定版。

查看curl 版本信息

curl --version

Armbian安装qbittorrent下载服务

安装qbittorrent

apt install qbittorrent-nox

添加到系统服务
vim /etc/systemd/system/qbittorrent-nox.service

[Unit]
Description=qBittorrent-nox
After=network.target

[Service]
User=root
Type=forking
RemainAfterExit=yes
ExecStart=/usr/bin/qbittorrent-nox -d

[Install]
WantedBy=multi-user.target

开机自启systemctl enable qbittorrent-nox.service
启动服务systemctl start qbittorrent-nox.service

默认web访问端口8080,用户名admin,密码adminadmin

Armbian自动挂载硬盘

查看系统所检测到的磁盘,这里的 sda1检测到的硬盘但是没有被挂载(注意:这里sda1 是’1’ 而不是’L’,有些可能是sdb1

lsblk         //查看信息

在根目录新建一个目录用于挂载硬盘,命令如下:

cd /.               //进入根目录
mkdir mnts            //新建目录名为‘mnts’可用'ls'查看

挂载新增的磁盘sda1(所有新增硬盘都在/dev/目录下)

mount /dev/sda1 /mnts/        //挂载到mnts
cd /mnts/                //进入挂载的硬盘 'ls'查看内容

开机自动挂载:

这条命令可以显示硬盘信息,并记下UUID,为下一步做准备,这里以sda1为例

blkid /dev/sda1

修改 /etc/fstab 即可。例如我就是在 fstab 最后添加这行:

UUID=722059EC2059B835   /mnts      ntfs    defaults        0 0
vi /etc/fstab         //修改fstab

最后保存并应用, 则成功自定挂载,开机也会自动挂载(注意:这里只对只一个硬盘有效)

mount -a             //应用并启动

Armbian使用Docker安装IPsec VPN 服务器

项目地址:https://github.com/hwdsl2/setup-ipsec-vpn
首先获取镜像

docker pull hwdsl2/ipsec-vpn-server

创建配置文件config.env

# Note: All the variables to this image are optional.
# See README for more information.
# To use, uncomment and replace with your own values.

# Define IPsec PSK, VPN username and password
# - DO NOT put "" or '' around values, or add space around =
# - DO NOT use these special characters within values: \ " '
VPN_IPSEC_PSK=密钥
VPN_USER=账号
VPN_PASSWORD=密码

# Define additional VPN users
# - DO NOT put "" or '' around values, or add space around =
# - DO NOT use these special characters within values: \ " '
# - Usernames and passwords must be separated by spaces
# VPN_ADDL_USERS=additional_username_1 additional_username_2
# VPN_ADDL_PASSWORDS=additional_password_1 additional_password_2

# Use a DNS name for the VPN server
# - The DNS name must be a fully qualified domain name (FQDN)
# VPN_DNS_NAME=vpn.example.com

# Specify a name for the first IKEv2 client
# - Use one word only, no special characters except '-' and '_'
# - The default is 'vpnclient' if not specified
# VPN_CLIENT_NAME=your_client_name

# Use alternative DNS servers
# - By default, clients are set to use Google Public DNS
# - Example below shows Cloudflare's DNS service
# VPN_DNS_SRV1=1.1.1.1
# VPN_DNS_SRV2=1.0.0.1

# Protect IKEv2 client config files using a password
# - By default, no password is required when importing IKEv2 client configuration
# - Uncomment if you want to protect these files using a random password
# VPN_PROTECT_CONFIG=yes

运行镜像

docker run -d \
    -p 500:500/udp \
    -p 4500:4500/udp \
    --privileged=true \ # 特权模式运行
    --restart=always \  # 开启自启动
    --name ipsec-vpn-server \
    --env-file /home/iuu/Software/Docker/ipsec-vpn-server/config.env \ # 加载配置文件
    -v /home/iuu/Software/Docker/ipsec-vpn-server/ikev2-vpn-data:/etc/ipsec.d \
    -v /lib/modules:/lib/modules:ro \ # 挂载运行库目录 但是只有只读权限
    hwdsl2/ipsec-vpn-server

启动容器后查看容器状态
防火墙开4500 500 UDP端口
如果是内网穿透,路由器也得做对应的端口转发

1 2 3