error: ImportError: cannot import name '__all__'
Opened this issue · 1 comments
godmar commented
Hi,
I'm trying to use pypy-traceview. On Python 3.6, I get:
Traceback (most recent call last):
File "./pypy-traceview", line 12, in <module>
from pypy_traceview.renderer.html import render
File "/home/staff/gback/python/pypy-traceview/pypy_traceview/renderer/html.py", line 2, in <module>
from jinja2 import Template
File "/home/staff/gback/python/venv/lib/python3.6/site-packages/jinja2/__init__.py", line 8, in <module>
from .environment import Environment as Environment
File "/home/staff/gback/python/venv/lib/python3.6/site-packages/jinja2/environment.py", line 17, in <module>
from . import nodes
File "/home/staff/gback/python/venv/lib/python3.6/site-packages/jinja2/nodes.py", line 5, in <module>
import inspect
File "/usr/lib64/python3.6/inspect.py", line 36, in <module>
import dis
File "/usr/lib64/python3.6/dis.py", line 9, in <module>
from opcode import __all__ as _opcodes_all
ImportError: cannot import name '__all__'
I get the same error on Python 3.10:
$ PYTHONPATH=. ../venv/bin/pipenv run ./pypy-traceview ../logfile
Courtesy Notice: Pipenv found itself running within a virtual environment, so it will automatically use that environment, instead of creating its own for any project. You can set PIPENV_IGNORE_VIRTUALENVS=1 to force pipenv to ignore that environment and create its own instead. You can set PIPENV_VERBOSITY=-1 to suppress this warning.
Traceback (most recent call last):
File "/home/gback/icpc/icpc-fall-2022/pickupsticks/pypy-traceview/./pypy-traceview", line 4, in <module>
import pstats
File "/usr/lib/python3.10/pstats.py", line 31, in <module>
from dataclasses import dataclass
File "/usr/lib/python3.10/dataclasses.py", line 5, in <module>
import inspect
File "/usr/lib/python3.10/inspect.py", line 38, in <module>
import dis
File "/usr/lib/python3.10/dis.py", line 9, in <module>
from opcode import __all__ as _opcodes_all
ImportError: cannot import name '__all__' from 'opcode' (/home/gback/icpc/icpc-fall-2022/pickupsticks/pypy-traceview/pypy_traceview/opcode.py)
It seems that you are importing dis which in turn imports opcode
but due to the PYTHONPATH
setting picks up your version instead of the system version. I note that /usr/lib/python3.10/opcode.py
has an __all__
export.
godmar commented
I was able to rename opcode.py
to opcode_local.py
and apply this patch:
iff --git a/pypy_traceview/opcode_test.py b/pypy_traceview/opcode_test.py
index ecc87ac..4cf0c06 100644
--- a/pypy_traceview/opcode_test.py
+++ b/pypy_traceview/opcode_test.py
@@ -1,4 +1,4 @@
-from .opcode import Opcode, group_opcodes, indent_opcodes, \
+from .opcode_local import Opcode, group_opcodes, indent_opcodes, \
dump_indentend_opcodes
diff --git a/pypy_traceview/renderer/html.py b/pypy_traceview/renderer/html.py
index d3c7f4d..aee7748 100644
--- a/pypy_traceview/renderer/html.py
+++ b/pypy_traceview/renderer/html.py
@@ -6,7 +6,7 @@ from pygments.lexers import PythonLexer, NasmLexer, GasLexer
from pygments.token import Comment
from pygments.formatters import HtmlFormatter
-from ..opcode import group_opcodes, indent_opcodes, Opcode
+from ..opcode_local import group_opcodes, indent_opcodes, Opcode
from ..ir import group_ir
from ..memoization import memoized
diff --git a/pypy_traceview/tracelog.py b/pypy_traceview/tracelog.py
index c7d5029..190a10d 100644
--- a/pypy_traceview/tracelog.py
+++ b/pypy_traceview/tracelog.py
@@ -1,4 +1,4 @@
-from .opcode import Opcode
+from .opcode_local import Opcode
class TraceLog:
this then made it work.