开发者

Bad magic number error persists even after rebuilding the .pyc file

When running a Python 3 script of mine, I encounter a "Bad magic number" error (while the script tries to import another module). A开发者_运维问答t first I imagined it's because there are .pyc files built by Python 2. I deleted the __pycache__ directory and reran the script, but the interpreter still gives me the same error when importing that module. Any ideas?

UPDATE: To clarify, I should mention that the import statement in the script doesn't cause the error by itself. Here's the stack trace:

Traceback (most recent call last):
  File "../mvc/test.py", line 6, in <module>
    from property import Property
  File "/home/mostafa/python/mvc/property.py", line 1, in <module>
    from owned import owned
  File "/home/mostafa/python/owned/__init__.py", line 1, in <module>
    from list import OwnedList
ImportError: Bad magic number in /home/mostafa/python/list.pyc


The last line of the stack trace shows the path to the pyc file causing the error:

ImportError: Bad magic number in /home/mostafa/python/list.pyc

Assuming you have list.py in your PYTHONPATH, you can delete /home/mostafa/python/list.pyc. When you import list, Python3 will generate a new version of list.pyc based on list.py.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜