在完成我的Python脚本之后,我想将我的脚本和所使用的库捆绑在一起,这样我就可以更容易地扩展我的脚本。
我尝试使用PiInstaller,但是我运行在dist文件夹上生成的脚本,得到模块bs4 (没有找到beautifullSoup)
I按如下方式进行:
我从我用命令“python3 -m venv”创建的虚拟环境目录中运行python3,如下所示:
$ /home/kfocal/.local/bin/pyinstaller podcast_apple.py
31 INFO: PyInstaller: 4.2
31 INFO: Python: 3.8.5
39 INFO: Platform: Linux-5.4.0-65-generic-x86_64-with-glibc2.29
42 INFO: wrote /home/focal/Documents/python/Kdata/env/podcast_apple.spec
45 INFO: UPX is not available.
47 INFO: Extending PYTHONPATH with paths
['/home/focal/Documents/python/Kdata/env',
'/home/focal/Documents/python/Kdata/env']
54 INFO: checking Analysis
54 INFO: Building Analysis because Analysis-00.toc is non existent
54 INFO: Initializing module dependency graph...
55 INFO: Caching module graph hooks...
58 WARNING: Several hooks defined for module 'win32ctypes.core'. Please take care they do not conflict.
60 INFO: Analyzing base_library.zip ...
2102 INFO: Processing pre-find module path hook distutils from '/home/kfocal/.local/lib/python3.8/site-packages/PyInstaller/hooks/pre_find_module_path/hook-distutils.py'.
2103 INFO: distutils: retargeting to non-venv dir '/usr/lib/python3.8'
4053 INFO: Caching module dependency graph...
4137 INFO: running Analysis Analysis-00.toc
4160 INFO: Analyzing /home/focal/Documents/python/Kdata/env/podcast_apple.py
4235 INFO: Processing pre-safe import module hook six.moves from '/home/kfocal/.local/lib/python3.8/site-packages/PyInstaller/hooks/pre_safe_import_module/hook-six.moves.py'.
5794 INFO: Processing module hooks...
5794 INFO: Loading module hook 'hook-certifi.py' from '/home/kfocal/.local/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
5796 INFO: Loading module hook 'hook-cryptography.py' from '/home/kfocal/.local/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
5949 INFO: Loading module hook 'hook-distutils.util.py' from '/home/kfocal/.local/lib/python3.8/site-packages/PyInstaller/hooks'...
5952 INFO: Excluding import of lib2to3.refactor from module distutils.util
5952 INFO: Loading module hook 'hook-distutils.py' from '/home/kfocal/.local/lib/python3.8/site-packages/PyInstaller/hooks'...
5954 INFO: Loading module hook 'hook-multiprocessing.util.py' from '/home/kfocal/.local/lib/python3.8/site-packages/PyInstaller/hooks'...
5955 INFO: Excluding import of test from module multiprocessing.util
5955 INFO: Excluding import of test.support from module multiprocessing.util
5955 INFO: Loading module hook 'hook-xml.py' from '/home/kfocal/.local/lib/python3.8/site-packages/PyInstaller/hooks'...
6004 INFO: Loading module hook 'hook-lib2to3.py' from '/home/kfocal/.local/lib/python3.8/site-packages/PyInstaller/hooks'...
6011 INFO: Loading module hook 'hook-sysconfig.py' from '/home/kfocal/.local/lib/python3.8/site-packages/PyInstaller/hooks'...
6021 INFO: Loading module hook 'hook-difflib.py' from '/home/kfocal/.local/lib/python3.8/site-packages/PyInstaller/hooks'...
6024 INFO: Excluding import of doctest from module difflib
6024 INFO: Loading module hook 'hook-pickle.py' from '/home/kfocal/.local/lib/python3.8/site-packages/PyInstaller/hooks'...
6025 INFO: Excluding import of argparse from module pickle
6025 INFO: Loading module hook 'hook-heapq.py' from '/home/kfocal/.local/lib/python3.8/site-packages/PyInstaller/hooks'...
6027 INFO: Excluding import of doctest from module heapq
6027 INFO: Loading module hook 'hook-encodings.py' from '/home/kfocal/.local/lib/python3.8/site-packages/PyInstaller/hooks'...
6064 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from '/home/kfocal/.local/lib/python3.8/site-packages/PyInstaller/hooks'...
6080 INFO: Looking for ctypes DLLs
6104 INFO: Analyzing run-time hooks ...
6107 INFO: Including run-time hook '/home/kfocal/.local/lib/python3.8/site-packages/PyInstaller/hooks/rthooks/pyi_rth_multiprocessing.py'
6111 INFO: Including run-time hook '/home/kfocal/.local/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/rthooks/pyi_rth_certifi.py'
6121 INFO: Looking for dynamic libraries
6500 INFO: Looking for eggs
6500 INFO: Python library not in binary dependencies. Doing additional searching...
6546 INFO: Using Python library /lib/x86_64-linux-gnu/libpython3.8.so.1.0
6554 INFO: Warnings written to /home/focal/Documents/python/Kdata/env/build/podcast_apple/warn-podcast_apple.txt
6582 INFO: Graph cross-reference written to /home/focal/Documents/python/Kdata/env/build/podcast_apple/xref-podcast_apple.html
6591 INFO: checking PYZ
6591 INFO: Building PYZ because PYZ-00.toc is non existent
6591 INFO: Building PYZ (ZlibArchive) /home/focal/Documents/python/Kdata/env/build/podcast_apple/PYZ-00.pyz
7080 INFO: Building PYZ (ZlibArchive) /home/focal/Documents/python/Kdata/env/build/podcast_apple/PYZ-00.pyz completed successfully.
7084 INFO: checking PKG
7084 INFO: Building PKG because PKG-00.toc is non existent
7084 INFO: Building PKG (CArchive) PKG-00.pkg
7126 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
7127 INFO: Bootloader /home/kfocal/.local/lib/python3.8/site-packages/PyInstaller/bootloader/Linux-64bit/run
7127 INFO: checking EXE
7127 INFO: Building EXE because EXE-00.toc is non existent
7127 INFO: Building EXE from EXE-00.toc
7128 INFO: Appending archive to ELF section in EXE /home/focal/Documents/python/Kdata/env/build/podcast_apple/podcast_apple
7138 INFO: Building EXE from EXE-00.toc completed successfully.
7139 INFO: checking COLLECT
7139 INFO: Building COLLECT because COLLECT-00.toc is non existent
7140 INFO: Building COLLECT COLLECT-00.toc
7158 INFO: Building COLLECT COLLECT-00.toc completed successfully.您可以注意到,一切似乎都很好,但是我知道bs4模块已经丢失了。
~/Documents/python/Kdata/env/dist/podcast_apple$ ./podcast_apple
Traceback (most recent call last):
File "podcast_apple.py", line 1, in <module>
ModuleNotFoundError: No module named 'bs4'
[81848] Failed to execute script podcast_apple而且,当我搜索corpingBS4时,我只能在我的dev库中找到。
~/Documents/python/Kdata/env$ find . -name "*bs4*"
./lib/python3.8/site-packages/bs4
./lib/python3.8/site-packages/bs4-0.0.1.egg-info我错过了什么吗?根据文档,piInstaller应该复制所有使用的模块。为什么pyInstaller错过了BS4?Mon脚本非常简单。
为了找出
,PyInstaller会在脚本中找到所有导入语句。它找到导入的模块,并递归地查找导入语句等等,直到它有了脚本可以使用的完整模块列表。
发布于 2022-07-30 23:50:27
我知道这个线程很旧,但是在我的虚拟环境中运行PyInstaller时,我也遇到了同样的问题。beautifulsoup4安装在我的虚拟主机中,但是PyInstaller似乎并没有添加这个包。在运行--hidden-import beautifulsoup4时添加PyInstaller也不能解决问题。
经过多次搜索,我终于找到了这个链接:https://groups.google.com/g/PyInstaller/c/0IOY5Xoevsg
我看到的建议是:
你能把它(PyInstaller)运行为
python -m PyInstaller [rest of the command here](而不是运行pyinstaller.exe [args])吗?
令人惊讶的是,这对我起了作用。我想我现在明白了发生了什么:我认为虽然我在一个安装了包的虚拟环境中,但是被调用的pyinstaller在错误的环境中(在我的虚拟环境之外?)--也许是因为我激活了虚拟化程序的顺序。
使用python -m ... 的
强制它使用正确的PyInstaller
更多的是:
,如果
python -m PyInstaller给出了一个名为PyInstaller error 的No模块,那么您的venv就是一团糟,而PyInstaller不在正确的环境中。使用python -m ...强制它使用正确的PyInstaller (不存在)。您路径中的PyInstaller可能是从其他旧环境(使用where PyInstaller查找哪个环境)还是根环境遗留下来的。
修复方法是使用以下方法在venv中安装PyInstaller:
venv\Scripts\activate pip install PyInstaller
验证PyInstaller现在指向的第一个(或仅)输出在venv/脚本中。
tl;博士:总之-
python -m PyInstaller [args]而不是pyinstaller.exe [args]的形式运行pyinstaller,试图强制它使用pyinstaller的正确上下文。
如果仍然不能工作,则通过运行pip install PyInstaller从虚拟env本身安装PyInstaller
希望这能帮上忙。
https://stackoverflow.com/questions/66392496
复制相似问题