python中解决ImportError: bad magic number in 'random': b'\x03\xf3\r\n
root@ubuntu# python3 randomtest.py
Traceback (most recent call last):
File "randomtest.py", line 5, in
import random
ImportError: bad magic number in 'random': b'\x03\xf3\r\n'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 12, in
import subprocess, tempfile, os.path, re, pwd, grp, os, time, io
File "/usr/lib/python3.5/tempfile.py", line 184, in
from random import Random as _Random
ImportError: bad magic number in 'random': b'\x03\xf3\r\n'
在终端输入ls -a 会出现一个.pyc的文件,将文件删掉
并且文件名和模块名不能相同不然会报错,因为python random模块的库文件就叫做random.py,
所以我们不能写这个一样的名字,换个名字,就可以了