暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

安装pyinstaller

原创 滕启天 2023-03-24
1196

操作系统版本

[root@docker dist]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core) 

python版本

[root@docker dist]# python3 --version
Python 3.6.8


一开始安装走进了死胡同

下载pyinstaller源码,进行安装

tar -xzvf pyinstaller-5.9.0.tar.gz
cd pyinstaller-5.9.0/
 python3 setup.py install

安装报错


在换个思路,下载了pip3,用pip3安装

[root@docker ~]# pip3 install pyinstaller
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting pyinstaller
Installing collected packages: pyinstaller
Exception:
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/usr/lib/python3.6/site-packages/pip/commands/install.py", line 365, in run
strip_file_prefix=options.strip_file_prefix,
File "/usr/lib/python3.6/site-packages/pip/req/req_set.py", line 789, in install
**kwargs
File "/usr/lib/python3.6/site-packages/pip/req/req_install.py", line 854, in install
strip_file_prefix=strip_file_prefix
File "/usr/lib/python3.6/site-packages/pip/req/req_install.py", line 1069, in move_wheel_files
strip_file_prefix=strip_file_prefix,
File "/usr/lib/python3.6/site-packages/pip/wheel.py", line 347, in move_wheel_files
assert info_dir, "%s .dist-info directory not found" % req
AssertionError: pyinstaller .dist-info directory not found

安装还是报错


忽然灵机一闪,是不是需要pip安装,而不是pip3安装

先安装pip

[root@docker ~]# python3 -m pip install --upgrade pip


WARNING: Running pip install with root privileges is generally not a good idea. Try `__main__.py install --user` instead.
Collecting pip
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fed9a5b1668>: Failed to establish a new connection: [Errno 101] Network is unreachable',)': /packages/a4/6d/6463d49a933f547439d6b5b98b46af8742cc03ae83543e4d7688c2420f8b/pip-21.3.1-py3-none-any.whl
Downloading https://files.pythonhosted.org/packages/a4/6d/6463d49a933f547439d6b5b98b46af8742cc03ae83543e4d7688c2420f8b/pip-21.3.1-py3-none-any.whl (1.7MB)
100% |████████████████████████████████| 1.7MB 9.8kB/s
Installing collected packages: pip
Successfully installed pip-21.3.1
You are using pip version 21.3.1, however version 23.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.



再用pip安装pyinstaller


[root@docker ~]# pip install pyinstaller
Collecting pyinstaller
Downloading pyinstaller-4.10-py3-none-manylinux2014_x86_64.whl (1.5 MB)
|████████████████████████████████| 1.5 MB 14 kB/s
Collecting pyinstaller-hooks-contrib>=2020.6
Downloading pyinstaller_hooks_contrib-2022.0-py2.py3-none-any.whl (222 kB)
|████████████████████████████████| 222 kB 12 kB/s
Collecting importlib-metadata
Downloading importlib_metadata-4.8.3-py3-none-any.whl (17 kB)
Requirement already satisfied: setuptools in /usr/local/lib/python3.6/site-packages (from pyinstaller) (43.0.0)
Collecting altgraph
Downloading altgraph-0.17.3-py2.py3-none-any.whl (21 kB)
Collecting typing-extensions>=3.6.4
Downloading typing_extensions-4.1.1-py3-none-any.whl (26 kB)
Collecting zipp>=0.5
Downloading zipp-3.6.0-py3-none-any.whl (5.3 kB)
Installing collected packages: zipp, typing-extensions, pyinstaller-hooks-contrib, importlib-metadata, altgraph, pyinstaller
Successfully installed altgraph-0.17.3 importlib-metadata-4.8.3 pyinstaller-4.10 pyinstaller-hooks-contrib-2022.0 typing-extensions-4.1.1 zipp-3.6.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv


最后,用pyinstaller编译python程序

[root@docker script]# pyinstaller -F d.py
157 INFO: PyInstaller: 4.10
157 INFO: Python: 3.6.8
158 INFO: Platform: Linux-3.10.0-862.el7.x86_64-x86_64-with-centos-7.5.1804-Core
159 INFO: wrote /script/d.spec
163 INFO: UPX is not available.
166 INFO: Extending PYTHONPATH with paths
['/script']
431 INFO: checking Analysis
431 INFO: Building Analysis because Analysis-00.toc is non existent
431 INFO: Initializing module dependency graph...
433 INFO: Caching module graph hooks...
463 INFO: Analyzing base_library.zip ...
5511 INFO: Caching module dependency graph...
5763 INFO: running Analysis Analysis-00.toc
5794 INFO: Analyzing /script/d.py
6330 INFO: Processing module hooks...
6331 INFO: Loading module hook 'hook-difflib.py' from '/usr/local/lib/python3.6/site-packages/UNKNOWN-0.0.0-py3.6.egg/PyInstaller/hooks'...
6336 INFO: Loading module hook 'hook-encodings.py' from '/usr/local/lib/python3.6/site-packages/UNKNOWN-0.0.0-py3.6.egg/PyInstaller/hooks'...
6474 INFO: Loading module hook 'hook-heapq.py' from '/usr/local/lib/python3.6/site-packages/UNKNOWN-0.0.0-py3.6.egg/PyInstaller/hooks'...
6484 INFO: Loading module hook 'hook-pickle.py' from '/usr/local/lib/python3.6/site-packages/UNKNOWN-0.0.0-py3.6.egg/PyInstaller/hooks'...
6489 INFO: Loading module hook 'hook-xml.py' from '/usr/local/lib/python3.6/site-packages/UNKNOWN-0.0.0-py3.6.egg/PyInstaller/hooks'...
6872 INFO: Looking for ctypes DLLs
6872 INFO: Analyzing run-time hooks ...
6877 INFO: Including run-time hook '/usr/local/lib/python3.6/site-packages/UNKNOWN-0.0.0-py3.6.egg/PyInstaller/hooks/rthooks/pyi_rth_subprocess.py'
6881 INFO: Including run-time hook '/usr/local/lib/python3.6/site-packages/UNKNOWN-0.0.0-py3.6.egg/PyInstaller/hooks/rthooks/pyi_rth_pkgutil.py'
6886 INFO: Including run-time hook '/usr/local/lib/python3.6/site-packages/UNKNOWN-0.0.0-py3.6.egg/PyInstaller/hooks/rthooks/pyi_rth_inspect.py'
6899 INFO: Looking for dynamic libraries
7605 INFO: Looking for eggs
7605 INFO: Using Python library /lib64/libpython3.6m.so.1.0
7611 INFO: Warnings written to /script/build/d/warn-d.txt
7655 INFO: Graph cross-reference written to /script/build/d/xref-d.html
7687 INFO: checking PYZ
7687 INFO: Building PYZ because PYZ-00.toc is non existent
7687 INFO: Building PYZ (ZlibArchive) /script/build/d/PYZ-00.pyz
8356 INFO: Building PYZ (ZlibArchive) /script/build/d/PYZ-00.pyz completed successfully.
8362 INFO: checking PKG
8362 INFO: Building PKG because PKG-00.toc is non existent
8362 INFO: Building PKG (CArchive) d.pkg
12850 INFO: Building PKG (CArchive) d.pkg completed successfully.
12853 INFO: Bootloader /usr/local/lib/python3.6/site-packages/UNKNOWN-0.0.0-py3.6.egg/PyInstaller/bootloader/Linux-64bit-intel/run
12853 INFO: checking EXE
12853 INFO: Building EXE because EXE-00.toc is non existent
12854 INFO: Building EXE from EXE-00.toc
12854 INFO: Copying bootloader EXE to /script/dist/d
12856 INFO: Appending PKG archive to custom ELF section in EXE
12983 INFO: Building EXE from EXE-00.toc completed successfully.
[root@docker script]# ll
total 5876
-rw-r--r-- 1 root root 57 Mar 22 19:25 a.py
-rw-r--r-- 1 root root 11 Mar 22 19:25 a.txt
-rw-r--r-- 1 root root 155 Mar 22 19:27 b.py
drwxr-xr-x 3 root root 15 Mar 24 00:09 build
-rw-r--r-- 1 root root 178 Mar 22 20:00 c.py
drwxr-xr-x 2 root root 15 Mar 24 00:09 dist
-rw-r--r-- 1 root root 734 Mar 22 23:21 d.py
-rw-r--r-- 1 root root 988 Mar 24 00:09 d.spec
drwxr-xr-x 6 501 games 205 Mar 22 20:25 pip-8.0.2
-rw-r--r-- 1 root root 1130183 Feb 26 2020 pip-8.0.2.tar.gz
drwxr-xr-x 2 root root 30 Mar 24 00:09 __pycache__
drwxrwxrwx 9 root root 260 Mar 22 23:36 pyinstaller-4.10
-rw-r--r-- 1 root root 2710187 Mar 5 2022 pyinstaller-4.10.tar.gz
drwxr-xr-x 10 501 games 4096 Mar 22 20:22 setuptools-19.6
-rw-r--r-- 1 root root 641502 Feb 26 2020 setuptools-19.6.tar.gz
drwxr-xr-x 14 501 games 4096 Mar 23 00:36 zlib-1.2.13
-rw-r--r-- 1 root root 1497445 Mar 23 00:33 zlib-1.2.13.tar.gz
[root@docker script]# cd dist/
[root@docker dist]# ll
total 6732
-rwxr-xr-x 1 root root 6890256 Mar 24 00:09 d

执行编译脚本。一个sql查询.

[root@docker dist]# service mysql start
Starting MySQL....... SUCCESS! 


[root@docker dist]# ./d
2 root 127.0.0.1:50358 Query 0



「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论