centos8 安装python3、pip、pyinstaller

centos8安装python3
安装python3:https://www.cnblogs.com/qq931399960/p/11664594.html


```bash
# 步骤:1、输入python3看有没有 
# 2、使用yum -y install python 安装 
# 3、指定版本安装:yum -y install python39
[root@localhost ~]# python3
-bash: python3: command not found
[root@localhost ~]# python
-bash: python: command not found
[root@localhost ~]# whereis python
python: /usr/lib/python3.6 /usr/lib64/python3.6 /usr/include/python3.6m /usr/share/man/man1/python.1.gz

[root@localhost ~]# yum -y install python
Repository extras is listed more than once in the configuration
Last metadata expiration check: 1:57:22 ago on Tue 18 Jun 2024 09:25:45 AM CST.
No match for argument: python
There are following alternatives for "python": python2, python36, python38, python39
Error: Unable to find a match: python
# 需要指定版本
[root@localhost ~]# yum -y install python39
# 安装省略
Repository extras is listed more than once in the configuration
Complete!

在这里插入代码片

安装pyinstall
[安装pyinstaller](https://www.jianshu.com/p/1614723f3197)



 
 第一种方法:下载PyInstaller进行安装
```cpp
wget -c https://github.com/pyinstaller/pyinstaller/releases/download/v3.3.1/PyInstaller-3.3.1.tar.gz
tar -zxvf PyInstaller-3.3.1.tar.gz
python setup.py install
pyinstaller --version

第一种方法:使用pip安装(推荐)


centos8 python3安装 pyinstaller
在CentOS 8上安装Python 3和PyInstaller,你可以按照以下步骤操作:

首先,确保系统已安装了Python 3。如果没有安装,可以使用以下命令安装Python 3:

sudo dnf install python3
接下来,安装PyInstaller。你可以使用pip,但首先需要确保你有pip3:

sudo dnf install python3-pip
然后,使用pip3安装PyInstaller:

pip3 install pyinstaller
验证PyInstaller是否安装成功:

pyinstaller --version
如果你遇到权限问题,请确保你有正确的权限来安装软件包,或者使用sudo执行命令。如果PyInstaller不是通过Python 3的pip安装的,你可能需要使用pip3来安装。

报错解决

1、缺少gcc、clang、icc
No precompiled bootloader found or compile forced. Trying to compile the bootloader for you ...
  Setting top to                           : /tmp/pip-build-_sw7c23l/pyinstaller/bootloader
  Setting out to                           : /tmp/pip-build-_sw7c23l/pyinstaller/bootloader/build
  Python Version                           : 3.6.8 (default, Sep 10 2021, 09:13:53) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]
  Checking for 'gcc' (C compiler)          : not found
  Checking for 'clang' (C compiler)        : not found
  Checking for 'icc' (C compiler)          : not found
  could not configure a C compiler!
  (complete log in /tmp/pip-build-_sw7c23l/pyinstaller/bootloader/build/config.log)
  ERROR: Failed compiling the bootloader. Please compile manually and rerun setup.py

  ----------------------------------------
  Failed building wheel for pyinstaller
  Running setup.py clean for pyinstaller
Failed to build pyinstaller
Installing collected packages: altgraph, pyinstaller-hooks-contrib, typing-extensions, zipp, importlib-metadata, pyinstaller
  Running setup.py install for pyinstaller ... error

解决方法:

 yum -y install gcc
 yum -y install make zlib-devel gcc-c++ libtool openssl openssl-devel
yum -y install clang
yum -y install icc

更换pip源

修改 /etc/pip.conf 文件:

1.执行命令:vi /etc/pip.conf 编辑 pip.conf 配置文件

2.按下 i 键插入,输入如下内容,按下 esc,:wq 保存退出
[global]
index-url=https://pypi.tuna.tsinghua.edu.cn/simple

此时使用 pip 下载第三方包时就会使用配置好的 pip 源进行下载:

[root@localhost py]# pip3 install flask
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting flask
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/cd/77/59df23681f4fd19b7cbbb5e92484d46ad587554f5d490f33ef907e456132/Flask-2.0.3-py3-none-any.whl (95kB)
    100% |████████████████████████████████| 102kB 293kB/s
Collecting itsdangerous>=2.0 (from flask)

pyinstaller打包

默认打包命令,进入到需要打包的目录下
在这里插入图片描述

#打包命令,等待打包完成后
pyinstaller main.py

在这里插入图片描述
进入到dist目录下

cd /dist/main
# 运行
./main
# 结果:
[root@localhost main]# ./main
 * Serving Flask app 'main' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on all addresses.
   WARNING: This is a development server. Do not use it in a production deployment.
 * Running on http://192.168.145.129:5000/ (Press CTRL+C to quit)
指定的服务器地址和端口:app.run(host='0.0.0.0',port=5000)

编写测试python程序
vim test.py

#!/usr/bin/python -w
# -*- coding:utf8 -*-

import os

def main():
    print("print the result of 'ls -al':")
    print("这是一个测试代码")
    os.system("ls -al")

if __name__ == '__main__':
    main()

使用python程序直接调用该程序,结果如下:


[root@localhost soft]# python3 test.py
print the result of 'ls -al':
这是一个测试的python
总用量 3392
drwxr-xr-x.  6 root root     139 617 20:31 .
drwxr-xr-x. 15 root root     170 617 20:07 ..
drwxr-xr-x.  3 root root      18 617 20:31 build
drwxr-xr-x.  2 root root      18 617 20:31 dist
drwxr-xr-x.  2 root root      33 617 20:31 __pycache__
drwxr-xr-x.  9 1000 1000    4096 617 20:15 PyInstaller-3.3.1
-rw-r--r--.  1 root root 3458638 127 2021 PyInstaller-3.3.1.tar.gz
-rw-r--r--.  1 root root     214 617 20:13 test.py
-rw-r--r--.  1 root root     709 617 20:31 test.spec

大写的-F表示生成单一文件。

pyinstaller -F test.py

运行结果:


[root@localhost soft]# pyinstaller -F test.py
29 INFO: PyInstaller: 3.3.1
29 INFO: Python: 3.6.8
4630 INFO: Building EXE from out00-EXE.toc completed successfully.

查看目录:

[root@localhost soft]# ll
总用量 8
drwxr-xr-x. 3 root root  18 617 20:31 build
drwxr-xr-x. 2 root root  18 617 20:31 dist
drwxr-xr-x. 2 root root  33 617 20:31 __pycache__
-rw-r--r--. 1 root root 214 617 20:13 test.py
-rw-r--r--. 1 root root 709 617 20:31 test.spec

dist就是打包结果目录,进入直接运行:

[root@localhost soft]# cd dist/
[root@localhost dist]# ll
总用量 6156
-rwxr-xr-x. 1 root root 6300160 617 20:31 test
[root@localhost dist]# ./test
print the result of 'ls -al':
这是一个测试的python
总用量 6156
drwxr-xr-x. 2 root root      18 617 20:31 .
drwxr-xr-x. 5 root root      82 617 20:36 ..
-rwxr-xr-x. 1 root root 6300160 617 20:31 test

docker打包python程序
docker打包python程序:https://developer.baidu.com/article/details/2805093

详细:https://www.jb51.net/python/3144726ij.htm

全过程:
https://blog.csdn.net/zxstone/article/details/138638918?utm_medium=distribute.pc_relevant.none-task-blog-2defaultbaidujs_baidulandingword~default-8-138638918-blog-130821367.235v43pc_blog_bottom_relevance_base8&spm=1001.2101.3001.4242.5&utm_relevant_index=11

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值