centos8 安装python3、pip、pyinstaller
centos8安装python3在这里插入代码片安装pyinstall第一种方法:下载PyInstaller进行安装第一种方法:使用pip安装(推荐)
centos8安装python3
安装python3:https://www.cnblogs.com/qq931399960/p/11664594.html
一、安装python3
# 步骤:1、输入python3看有没有
[root@localhost ~]# python3 -V
# 安装python需要指定版本,这里直接安装python36
[root@localhost ~]# yum install python
Repository extras is listed more than once in the configuration
Last metadata expiration check: 2:12:07 ago on Tue 13 Aug 2024 02:10:50 PM CST.
No match for argument: python
There are following alternatives for "python": python2, python36, python38, python39
安装命令:
[root@localhost ~]# yum install python36
结果:
Repository extras is listed more than once in the configuration
Last metadata expiration check: 2:12:14 ago on Tue 13 Aug 2024 02:10:50 PM CST.
Dependencies resolved.
=============================================================================================================================
Package Architecture Version Repository Size
=============================================================================================================================
Installing:
python36 x86_64 3.6.8-38.module_el8.5.0+895+a459eca8 AppStream 19 k
Installing dependencies:
python3-pip noarch 9.0.3-20.el8 AppStream 20 k
Enabling module streams:
python36 3.6
Transaction Summary
=============================================================================================================================
Install 2 Packages
Total download size: 39 k
Installed size: 16 k
Is this ok [y/N]: y
Downloading Packages:
(1/2): python3-pip-9.0.3-20.el8.noarch.rpm 8.6 kB/s | 20 kB 00:02
(2/2): python36-3.6.8-38.module_el8.5.0+895+a459eca8.x86_64.rpm 8.3 kB/s | 19 kB 00:02
-----------------------------------------------------------------------------------------------------------------------------
Total 17 kB/s | 39 kB 00:02
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : python36-3.6.8-38.module_el8.5.0+895+a459eca8.x86_64 1/2
Running scriptlet: python36-3.6.8-38.module_el8.5.0+895+a459eca8.x86_64 1/2
Installing : python3-pip-9.0.3-20.el8.noarch 2/2
Running scriptlet: python3-pip-9.0.3-20.el8.noarch 2/2
Verifying : python3-pip-9.0.3-20.el8.noarch 1/2
Verifying : python36-3.6.8-38.module_el8.5.0+895+a459eca8.x86_64 2/2
Installed:
python3-pip-9.0.3-20.el8.noarch python36-3.6.8-38.module_el8.5.0+895+a459eca8.x86_64
Complete!
安装完成,使用命令查看版本
[root@localhost ~]# python3 -V
Python 3.6.8
[root@localhost ~]# whereis python
python: /usr/bin/python3.6 /usr/bin/python3.6m /usr/lib/python3.6 /usr/lib64/python3.6 /usr/include/python3.6m /usr/share/man/man1/python.1.gz
二、更换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
测试命令:pip3 install flask
查看安装目录:
[root@localhost ~]# python3
Python 3.6.8 (default, Sep 10 2021, 09:13:53)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
# 输入以下命令 然后回车:
>>> import site
>>> print(site.getsitepackages())
['/usr/local/lib64/python3.6/site-packages', '/usr/local/lib/python3.6/site-packages', '/usr/lib64/python3.6/site-packages', '/usr/lib/python3.6/site-packages']
查看文件夹大小:
du -sh /usr/local/lib64/python3.6/site-packages
du -sh /usr/local/lib/python3.6/site-packages
du -sh /usr/lib64/python3.6/site-packages
du -sh /usr/lib/python3.6/site-packages
可以看到文件夹大小:
[root@localhost site-packages]# du -sh /usr/local/lib64/python3.6/site-packages
2.1G /usr/local/lib64/python3.6/site-packages
[root@localhost site-packages]# ^C
[root@localhost site-packages]# du -sh /usr/local/lib/python3.6/site-packages
34M /usr/local/lib/python3.6/site-packages
[root@localhost site-packages]# du -sh /usr/lib64/python3.6/site-packages
24M /usr/lib64/python3.6/site-packages
[root@localhost site-packages]# du -sh /usr/lib/python3.6/site-packages
32M /usr/lib/python3.6/site-packages
三、安装PyInstaller
参考:https://www.jianshu.com/p/1614723f3197
查看是否安装pip3,可以看到已经有了
[root@localhost ~]# pip3 -V
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)
安装pyinstaller之前先安装依赖包:
pip3 install wheel
yum -y install gcc
yum -y install clang
yum -y install zlib-devel
最后安装pyinstaller:
pip3 install pyinstaller
结果:
[root@localhost ~]# pip3 install pyinstaller
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting pyinstaller
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/b0/e6/e5760666896739115b0e4538a42cdd895215581618ec885ad043dd35ee57/pyinstaller-4.10.tar.gz
Requirement already satisfied: setuptools in /usr/lib/python3.6/site-packages (from pyinstaller)
Requirement already satisfied: altgraph in /usr/local/lib/python3.6/site-packages (from pyinstaller)
Requirement already satisfied: pyinstaller-hooks-contrib>=2020.6 in /usr/local/lib/python3.6/site-packages (from pyinstaller)
Requirement already satisfied: importlib-metadata in /usr/local/lib/python3.6/site-packages (from pyinstaller)
Requirement already satisfied: typing-extensions>=3.6.4; python_version < "3.8" in /usr/local/lib/python3.6/site-packages (from importlib-metadata->pyinstaller)
Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.6/site-packages (from importlib-metadata->pyinstaller)
Building wheels for collected packages: pyinstaller
Running setup.py bdist_wheel for pyinstaller ... done
Stored in directory: /root/.cache/pip/wheels/86/1d/7e/c1c7c4778f6f93f932ac74759fdef0c5ac801be636e35ec887
Successfully built pyinstaller
Installing collected packages: pyinstaller
Successfully installed pyinstaller-4.10
安装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
解决方法:
pip3 install wheel
yum -y install gcc
yum -y install make zlib-devel gcc-c++ libtool openssl openssl-devel
yum -y install clang
yum -y install icc
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 6月 17 20:31 .
drwxr-xr-x. 15 root root 170 6月 17 20:07 ..
drwxr-xr-x. 3 root root 18 6月 17 20:31 build
drwxr-xr-x. 2 root root 18 6月 17 20:31 dist
drwxr-xr-x. 2 root root 33 6月 17 20:31 __pycache__
drwxr-xr-x. 9 1000 1000 4096 6月 17 20:15 PyInstaller-3.3.1
-rw-r--r--. 1 root root 3458638 12月 7 2021 PyInstaller-3.3.1.tar.gz
-rw-r--r--. 1 root root 214 6月 17 20:13 test.py
-rw-r--r--. 1 root root 709 6月 17 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 6月 17 20:31 build
drwxr-xr-x. 2 root root 18 6月 17 20:31 dist
drwxr-xr-x. 2 root root 33 6月 17 20:31 __pycache__
-rw-r--r--. 1 root root 214 6月 17 20:13 test.py
-rw-r--r--. 1 root root 709 6月 17 20:31 test.spec
dist就是打包结果目录,进入直接运行:
[root@localhost soft]# cd dist/
[root@localhost dist]# ll
总用量 6156
-rwxr-xr-x. 1 root root 6300160 6月 17 20:31 test
[root@localhost dist]# ./test
print the result of 'ls -al':
这是一个测试的python
总用量 6156
drwxr-xr-x. 2 root root 18 6月 17 20:31 .
drwxr-xr-x. 5 root root 82 6月 17 20:36 ..
-rwxr-xr-x. 1 root root 6300160 6月 17 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
更多推荐
所有评论(0)