我正在使用 Python 3 中的 Think Python 一书执行代码。代码如下。
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
import urllib.request
conn = urllib.request.urlopen('http://thinkpython.com/secret.html')
for line in conn:
print(line.strip())
当我在机器的终端中执行此代码时,得到以下输出。
Traceback (most recent call last): File "secret.py", line 4, in <module> import urllib.request File "/usr/lib/python3.6/urllib/request.py", line 84, in <module> import base64 File "/usr/lib/python3.6/base64.py", line 10, in <module> import struct File "/usr/lib/python3.6/struct.py", line 13, in <module> from _struct import * ModuleNotFoundError: No module named '_struct' 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 <module> from apport.report import Report File "/usr/lib/python3/dist-packages/apport/report.py", line 12, in <module> import subprocess, tempfile, os.path, re, pwd, grp, os, time File "/usr/lib/python3.6/subprocess.py", line 136, in <module> import _posixsubprocess ModuleNotFoundError: No module named '_posixsubprocess' Original exception was: Traceback (most recent call last): File "secret.py", line 4, in <module> import urllib.request File "/usr/lib/python3.6/urllib/request.py", line 84, in <module> import base64 File "/usr/lib/python3.6/base64.py", line 10, in <module> import struct File "/usr/lib/python3.6/struct.py", line 13, in <module> from _struct import * ModuleNotFoundError: No module named '_struct'
我在Anaconda中执行了相同的代码,并且得到了正确的输出。任何人都可以帮助我解决这个问题。