我正在尝试使用Nuitka编译一个简单的独立python应用程序。我只使用标准库就可以做到这一点。
我现在希望带来一些额外的依赖,但是我现在收到无法解释的来自Nuitka的错误。
我尝试将numpy导入到如下项目中:
结构:
这里是__main__.py
import numpy as np
def main():
print('hello Nuitka')
print('hello numpy', np.__version__)
if __name__ == '__main__':
main()
然后我运行python -m nuitka npg/__main__.py --standalone
并收到错误消息:
Nuitka:WARNING:/usr/local/lib/python3.6/site-packages/numpy/testing/_private/pytesttester.py:125: Cannot find 'pytest' in package 'numpy.testing._private' as absolute import (tried pytest).
Nuitka:WARNING:/usr/local/lib/python3.6/site-packages/setuptools/command/egg_info.py:20: Cannot find 'setuptools.extern.six.moves' in package 'setuptools.command' as absolute import (tried setuptools.extern.six.moves).
Nuitka:WARNING:/usr/local/lib/python3.6/site-packages/setuptools/command/egg_info.py:20: Cannot find 'setuptools.extern.six' in package 'setuptools.command' as absolute import (tried setuptools.extern.six).
Nuitka:WARNING:/usr/local/lib/python3.6/site-packages/setuptools/glob.py:13: Cannot find 'setuptools.extern.six' in package 'setuptools' as absolute import (tried setuptools.extern.six).
Nuitka:WARNING:Problem at '<SourceCodeReference to /usr/src/app/npg/__main__.py:4>' with FunctionDef(name='main', args=arguments(args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[]), body=[Expr(value=Call(func=Name(id='print', ctx=Load()), args=[Str(s='hello Nuitka')], keywords=[])), Expr(value=Call(func=Name(id='print', ctx=Load()), args=[Str(s='hello numpy'), Attribute(value=Name(id='np', ctx=Load()), attr='__version__', ctx=Load())], keywords=[]))], decorator_list=[], returns=None).
Problem with statement at /usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py:566:
-> from __main__ import __requires__
Problem with statement at /usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py:565:
-> try:
Problem with statement at /usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py:559:
-> @classmethod
Problem with statement at /usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py:559:
-> @classmethod
Problem with statement at /usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py:543:
-> class WorkingSet:
Problem with statement at /usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py:543:
-> class WorkingSet:
Problem with statement at /usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py:543:
-> class WorkingSet:
Problem with statement at /usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py:543:
-> class WorkingSet:
Nuitka:INFO:Interrupted while working on '<Node 'COMPILED_PYTHON_PACKAGE' with {'filename': '/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py', 'package': None, 'name': 'pkg_resources'}>'.
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/nuitka/__main__.py", line 218, in <module>
main()
File "/usr/local/lib/python3.6/site-packages/nuitka/__main__.py", line 212, in main
MainControl.main()
File "/usr/local/lib/python3.6/site-packages/nuitka/MainControl.py", line 800, in main
filename = filename
File "/usr/local/lib/python3.6/site-packages/nuitka/MainControl.py", line 152, in createNodeTree
Optimization.optimize(main_module.getOutputFilename())
File "/usr/local/lib/python3.6/site-packages/nuitka/optimizations/Optimization.py", line 533, in optimize
makeOptimizationPass(initial_pass = True)
File "/usr/local/lib/python3.6/site-packages/nuitka/optimizations/Optimization.py", line 446, in makeOptimizationPass
changed = optimizeModule(current_module)
File "/usr/local/lib/python3.6/site-packages/nuitka/optimizations/Optimization.py", line 173, in optimizeModule
changed = optimizeCompiledPythonModule(module)
File "/usr/local/lib/python3.6/site-packages/nuitka/optimizations/Optimization.py", line 97, in optimizeCompiledPythonModule
module.computeModule()
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/ModuleNodes.py", line 461, in computeModule
trace_collection = self.trace_collection
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/StatementNodes.py", line 165, in computeStatementsSequence
trace_collection
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/FrameNodes.py", line 195, in computeStatementsSequence
statement = statement
File "/usr/local/lib/python3.6/site-packages/nuitka/optimizations/TraceCollections.py", line 575, in onStatement
statement.computeStatement(self)
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/TryNodes.py", line 129, in computeStatement
trace_collection = trace_collection
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/StatementNodes.py", line 169, in computeStatementsSequence
statement = statement
File "/usr/local/lib/python3.6/site-packages/nuitka/optimizations/TraceCollections.py", line 575, in onStatement
statement.computeStatement(self)
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/AssignNodes.py", line 297, in computeStatement
trace_collection.onExpression(self.getAssignSource())
File "/usr/local/lib/python3.6/site-packages/nuitka/optimizations/TraceCollections.py", line 550, in onExpression
trace_collection = self
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/OutlineNodes.py", line 247, in computeExpressionRaw
trace_collection = trace_collection
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/StatementNodes.py", line 169, in computeStatementsSequence
statement = statement
File "/usr/local/lib/python3.6/site-packages/nuitka/optimizations/TraceCollections.py", line 575, in onStatement
statement.computeStatement(self)
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/TryNodes.py", line 129, in computeStatement
trace_collection = trace_collection
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/StatementNodes.py", line 169, in computeStatementsSequence
statement = statement
File "/usr/local/lib/python3.6/site-packages/nuitka/optimizations/TraceCollections.py", line 575, in onStatement
statement.computeStatement(self)
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/TryNodes.py", line 129, in computeStatement
trace_collection = trace_collection
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/StatementNodes.py", line 165, in computeStatementsSequence
trace_collection
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/FrameNodes.py", line 195, in computeStatementsSequence
statement = statement
File "/usr/local/lib/python3.6/site-packages/nuitka/optimizations/TraceCollections.py", line 575, in onStatement
statement.computeStatement(self)
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/LocalsDictNodes.py", line 406, in computeStatement
trace_collection = trace_collection
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/NodeBases.py", line 933, in computeStatementSubExpressions
expression = expression
File "/usr/local/lib/python3.6/site-packages/nuitka/optimizations/TraceCollections.py", line 550, in onExpression
trace_collection = self
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/ExpressionBases.py", line 976, in computeExpressionRaw
expression = trace_collection.onExpression(sub_expression)
File "/usr/local/lib/python3.6/site-packages/nuitka/optimizations/TraceCollections.py", line 550, in onExpression
trace_collection = self
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/ExpressionBases.py", line 976, in computeExpressionRaw
expression = trace_collection.onExpression(sub_expression)
File "/usr/local/lib/python3.6/site-packages/nuitka/optimizations/TraceCollections.py", line 550, in onExpression
trace_collection = self
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/ExpressionBases.py", line 976, in computeExpressionRaw
expression = trace_collection.onExpression(sub_expression)
File "/usr/local/lib/python3.6/site-packages/nuitka/optimizations/TraceCollections.py", line 550, in onExpression
trace_collection = self
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/FunctionNodes.py", line 901, in computeExpressionRaw
function_body.computeFunctionRaw(trace_collection)
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/FunctionNodes.py", line 408, in computeFunctionRaw
self.computeFunction(trace_collection)
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/FunctionNodes.py", line 422, in computeFunction
trace_collection = trace_collection
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/StatementNodes.py", line 169, in computeStatementsSequence
statement = statement
File "/usr/local/lib/python3.6/site-packages/nuitka/optimizations/TraceCollections.py", line 575, in onStatement
statement.computeStatement(self)
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/TryNodes.py", line 129, in computeStatement
trace_collection = trace_collection
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/StatementNodes.py", line 165, in computeStatementsSequence
trace_collection
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/FrameNodes.py", line 195, in computeStatementsSequence
statement = statement
File "/usr/local/lib/python3.6/site-packages/nuitka/optimizations/TraceCollections.py", line 575, in onStatement
statement.computeStatement(self)
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/TryNodes.py", line 129, in computeStatement
trace_collection = trace_collection
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/StatementNodes.py", line 169, in computeStatementsSequence
statement = statement
File "/usr/local/lib/python3.6/site-packages/nuitka/optimizations/TraceCollections.py", line 575, in onStatement
statement.computeStatement(self)
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/AssignNodes.py", line 297, in computeStatement
trace_collection.onExpression(self.getAssignSource())
File "/usr/local/lib/python3.6/site-packages/nuitka/optimizations/TraceCollections.py", line 550, in onExpression
trace_collection = self
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/ExpressionBases.py", line 1054, in computeExpressionRaw
expression = sub_expression
File "/usr/local/lib/python3.6/site-packages/nuitka/optimizations/TraceCollections.py", line 550, in onExpression
trace_collection = self
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/ExpressionBases.py", line 998, in computeExpressionRaw
trace_collection = trace_collection
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/ImportNodes.py", line 400, in computeExpression
module_name = imported_module_name
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/ImportNodes.py", line 290, in _attemptRecursion
module_package = module_package
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/ImportNodes.py", line 222, in _consider
reason = reason
File "/usr/local/lib/python3.6/site-packages/nuitka/importing/Recursion.py", line 169, in recurseTo
reason = reason
File "/usr/local/lib/python3.6/site-packages/nuitka/importing/Recursion.py", line 92, in _recurseTo
is_main = False
File "/usr/local/lib/python3.6/site-packages/nuitka/tree/Building.py", line 1055, in createModuleTree
is_main = is_main
File "/usr/local/lib/python3.6/site-packages/nuitka/tree/Building.py", line 760, in buildParseTree
source_ref = source_ref
File "/usr/local/lib/python3.6/site-packages/nuitka/tree/TreeHelpers.py", line 384, in buildStatementsNode
statements = buildNodeList(provider, nodes, source_ref, allow_none = True)
File "/usr/local/lib/python3.6/site-packages/nuitka/tree/TreeHelpers.py", line 338, in buildNodeList
entry = buildNode(provider, node, node_source_ref, allow_none)
File "/usr/local/lib/python3.6/site-packages/nuitka/tree/TreeHelpers.py", line 295, in buildNode
source_ref = source_ref
File "/usr/local/lib/python3.6/site-packages/nuitka/tree/ReformulationFunctionStatements.py", line 153, in buildFunctionNode
source_ref = source_ref
File "/usr/local/lib/python3.6/site-packages/nuitka/tree/ReformulationFunctionStatements.py", line 799, in buildFunctionWithParsing
source_ref = source_ref
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/FunctionNodes.py", line 452, in __init__
source_ref = source_ref
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/FunctionNodes.py", line 386, in __init__
setLocalsDictType(self.locals_dict_name, "python3_function")
File "/usr/local/lib/python3.6/site-packages/nuitka/nodes/LocalsScopes.py", line 30, in setLocalsDictType
assert locals_dict_name not in locals_dict_handles, locals_dict_name
AssertionError: locals___main__$$$function_1_main
我正在使用如何解释该错误。看起来Python的标准库导入机制的语法有问题。