【问题标题】:How to compile .py script which has request module by using Nuitka?如何使用 Nuitka 编译具有请求模块的 .py 脚本?
【发布时间】:2018-07-09 16:46:46
【问题描述】:

使用 Python = 3.6.5rc 版本。

当我运行这个命令时:

nuitka3 --portable pythonic.py

我得到了这个结果:

Nuitka:WARNING:/home/user/project/emblema:1: Cannot find '_frozen_importlib_external' in package 'emblema' as absolute import (tried _frozen_importlib_external).
Nuitka:WARNING:/usr/local/lib/python3.6/dist-packages/pyperclip/__init__.py:134: Cannot find 'gtk' in package 'pyperclip' as absolute import (tried gtk).
Nuitka:WARNING:/usr/local/lib/python3.6/dist-packages/pyperclip/__init__.py:159: Cannot find 'qtpy.QtWidgets' in package 'pyperclip' as absolute import (tried qtpy.QtWidgets).
Nuitka:WARNING:/usr/local/lib/python3.6/dist-packages/pyperclip/__init__.py:159: Cannot find 'qtpy' in package 'pyperclip' as absolute import (tried qtpy).
Nuitka:WARNING:/usr/local/lib/python3.6/dist-packages/pyperclip/__init__.py:474: Cannot find 'Foundation' in package 'pyperclip' as absolute import (tried Foundation).
Nuitka:WARNING:/usr/local/lib/python3.6/dist-packages/pyperclip/__init__.py:475: Cannot find 'AppKit' in package 'pyperclip' as absolute import (tried AppKit).
Nuitka:WARNING:Use '--plugin-enable=qt-plugins' for: Inclusion of Qt plugins.
Nuitka:WARNING:/home/stack/.local/lib/python3.6/site-packages/bs4/dammit.py:24: Cannot find 'cchardet' in package 'bs4' as absolute import (tried cchardet).
Nuitka:WARNING:/home/stack/.local/lib/python3.6/site-packages/bs4/dammit.py:44: Cannot find 'iconv_codec' in package 'bs4' as absolute import (tried iconv_codec).
Nuitka:WARNING:Use '--plugin-enable=pylint-warnings' for: Understand PyLint/PyDev annotations for warnings.
Nuitka:WARNING:/usr/lib/python3/dist-packages/html5lib/filters/alphabeticalattributes.py:8: Cannot find 'ordereddict' in package 'html5lib.filters' as absolute import (tried ordereddict).
Nuitka:WARNING:/usr/lib/python3/dist-packages/html5lib/treewalkers/etree.py:7: Cannot find 'ordereddict' in package 'html5lib.treewalkers' as absolute import (tried ordereddict).
Nuitka:WARNING:/usr/lib/python3/dist-packages/html5lib/treewalkers/genshi.py:3: Cannot find 'genshi.core' in package 'html5lib.treewalkers' as absolute import (tried genshi.core).
Nuitka:WARNING:/usr/lib/python3/dist-packages/html5lib/treewalkers/genshi.py:3: Cannot find 'genshi' in package 'html5lib.treewalkers' as absolute import (tried genshi).
Nuitka:WARNING:/usr/lib/python3/dist-packages/html5lib/html5parser.py:9: Cannot find 'ordereddict' in package 'html5lib' as absolute import (tried ordereddict).
Nuitka:WARNING:/usr/lib/python3/dist-packages/html5lib/_trie/datrie.py:3: Cannot find 'datrie' in package 'html5lib._trie' as absolute import (tried datrie).
Nuitka:WARNING:/usr/lib/python3/dist-packages/requests/compat.py:41: Cannot find 'urlparse' in package 'requests' as absolute import (tried urlparse).
Nuitka:WARNING:/usr/lib/python3/dist-packages/requests/compat.py:42: Cannot find 'urllib2' in package 'requests' as absolute import (tried urllib2).
Nuitka:WARNING:/usr/lib/python3/dist-packages/requests/compat.py:43: Cannot find 'cookielib' in package 'requests' as absolute import (tried cookielib).
Nuitka:WARNING:/usr/lib/python3/dist-packages/requests/compat.py:44: Cannot find 'Cookie' in package 'requests' as absolute import (tried Cookie).
Nuitka:WARNING:/usr/lib/python3/dist-packages/urllib3/packages/ordered_dict.py:11: Cannot find '_abcoll' in package 'urllib3.packages' as absolute import (tried _abcoll).
Nuitka:WARNING:/usr/lib/python3/dist-packages/urllib3/packages/ssl_match_hostname/__init__.py:13: Cannot find 'backports.ssl_match_hostname' in package 'urllib3.packages.ssl_match_hostname' as absolute import (tried backports.ssl_match_hostname).
Nuitka:WARNING:/usr/lib/python3/dist-packages/urllib3/packages/ssl_match_hostname/__init__.py:13: Cannot find 'backports' in package 'urllib3.packages.ssl_match_hostname' as absolute import (tried backports).
Nuitka:WARNING:/usr/lib/python3/dist-packages/urllib3/contrib/socks.py:27: Cannot find 'socks' in package 'urllib3.contrib' as absolute import (tried socks).
Nuitka:WARNING:/usr/lib/python3/dist-packages/asn1crypto/_iri.py:22: Cannot find 'urlparse' in package 'asn1crypto' as absolute import (tried urlparse).
Nuitka:WARNING:Unresolved '__import__' call at '/usr/lib/python3/dist-packages/requests/packages.py:7' may require use of '--recurse-directory'.

我需要使用哪个命令让 Nuitka 能够查看 requestsbs4 模块?

【问题讨论】:

    标签: python-3.x nuitka


    【解决方案1】:

    使用这个命令:

    nuitka3 --portable --recurse-directory pythonic.py
    

    如果这不起作用,那么,

    nuitka3 --portable --recurse-all pythonic.py
    

    或者在这个命令中使用 pyinstaller

    pip install pyinstaller
    pyinstaller --onefile pythonic.py
    

    【讨论】:

    • 使用 --recurse-directory 我得到了这个 --> 错误,需要 python 模块或主程序的位置参数。
    • @Anyuta 然后使用其他选项
    • 使用 --recurse-all 我得到了相同的 nuitka 警告:Nuitka:WARNING:/usr/local/lib/python3.6/dist-packages/pyperclip/__init__.py:134: Cannot find 'gtk' in package 'pyperclip' as absolute import (tried gtk). 等等
    • @Anyuta 这意味着 nuitka 无法构建独立的应用程序。抱歉,无法使用 pyinstaller 代替
    • Pyinstaller 通过添加 Python Interpreter + 源代码来创建“可执行文件”。并且 Pyinstallish 应用程序可以反编译。
    猜你喜欢
    • 1970-01-01
    • 2013-07-27
    • 1970-01-01
    • 2021-10-12
    • 2020-08-23
    • 1970-01-01
    • 2014-02-11
    • 2012-12-25
    • 1970-01-01
    相关资源
    最近更新 更多