当前位置: 首页 > news >正文

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/bootloaderSetting out to                           : /tmp/pip-build-_sw7c23l/pyinstaller/bootloader/buildPython 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 foundChecking for 'clang' (C compiler)        : not foundChecking for 'icc' (C compiler)          : not foundcould 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 pyinstallerRunning setup.py clean for pyinstaller
Failed to build pyinstaller
Installing collected packages: altgraph, pyinstaller-hooks-contrib, typing-extensions, zipp, importlib-metadata, pyinstallerRunning setup.py install for pyinstaller ... error

解决方法:

 yum -y install gccyum -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 flaskDownloading 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: productionWARNING: 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 osdef 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

相关文章:

  • SHELL脚本学习(十一)正则表达式
  • 机器学习算法的电影推荐系统以及票房预测系统
  • 【mysql 安装启动失败】 没有网下 libssl.so.10 not found 如何解决?
  • 拒绝零散碎片, 一文理清MySQL的各种锁
  • 网络基本概念
  • 驱动开发(三):内核层控制硬件层
  • 英文字母表
  • uniapp运行到模拟器(联想模拟器)
  • 数据结构与算法笔记:基础篇 - 分治算法:谈一谈大规模计算框架MapReduce中的分治思想
  • 苏泊尔超声波清洗机怎么样?苏泊尔、小泽医生、希亦多个维度测评
  • 酱香型白酒派系介绍
  • IntelBroker 黑客声称入侵了苹果公司,窃取了内部工具的源代码
  • Leetcode Java学习记录——代码随想录哈希表篇
  • C++ 线程池
  • 盘点:20个大幅提高效率的开源网络安全工具
  • [Vue CLI 3] 配置解析之 css.extract
  • 10个确保微服务与容器安全的最佳实践
  • 4月23日世界读书日 网络营销论坛推荐《正在爆发的营销革命》
  • Android 架构优化~MVP 架构改造
  • android 一些 utils
  • bootstrap创建登录注册页面
  • docker容器内的网络抓包
  • DOM的那些事
  • httpie使用详解
  • JavaScript 无符号位移运算符 三个大于号 的使用方法
  • JSDuck 与 AngularJS 融合技巧
  • open-falcon 开发笔记(一):从零开始搭建虚拟服务器和监测环境
  • php的插入排序,通过双层for循环
  • Spring框架之我见(三)——IOC、AOP
  • ⭐ Unity 开发bug —— 打包后shader失效或者bug (我这里用Shader做两张图片的合并发现了问题)
  • Vue--数据传输
  • 安装python包到指定虚拟环境
  • 计算机常识 - 收藏集 - 掘金
  • 如何进阶一名有竞争力的程序员?
  • 如何在GitHub上创建个人博客
  • d²y/dx²; 偏导数问题 请问f1 f2是什么意思
  • ​io --- 处理流的核心工具​
  • ​ubuntu下安装kvm虚拟机
  • ​人工智能书单(数学基础篇)
  • # linux 中使用 visudo 命令,怎么保存退出?
  • #1014 : Trie树
  • #Datawhale AI夏令营第4期#AIGC方向 文生图 Task2
  • (C语言)逆序输出字符串
  • (done) NLP “bag-of-words“ 方法 (带有二元分类和多元分类两个例子)词袋模型、BoW
  • (libusb) usb口自动刷新
  • (笔试题)分解质因式
  • (二)正点原子I.MX6ULL u-boot移植
  • (附源码)springboot家庭财务分析系统 毕业设计641323
  • (附源码)springboot猪场管理系统 毕业设计 160901
  • (附源码)springboot助农电商系统 毕业设计 081919
  • (附源码)ssm高校社团管理系统 毕业设计 234162
  • (附源码)计算机毕业设计SSM基于健身房管理系统
  • (过滤器)Filter和(监听器)listener
  • (紀錄)[ASP.NET MVC][jQuery]-2 純手工打造屬於自己的 jQuery GridView (含完整程式碼下載)...
  • (接口自动化)Python3操作MySQL数据库