ValueError:以10为底的int()的无效文字:''在python中导入请求模块时出错

时间:2018-09-15 14:24:03

标签: python python-3.x ubuntu-18.04

我正在使用Ubuntu 18.04 OS在Interactive Shell中导入请求模块时,发现以下错误 不知道为什么 我已经使用pip3安装了请求 如下 pip3安装请求以及当我尝试使用卸载请求时 pip3卸载请求运行良好,甚至在安装时也显示已成功安装了版本号

`

`>>> import requests


Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 888, in _find_spec
AttributeError: '_SixMetaPathImporter' object has no attribute 'find_spec'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/chaitu/.local/lib/python3.6/site-packages/requests/__init__.py", line 43, in <module>
    import urllib3
  File "/home/chaitu/.local/lib/python3.6/site-packages/urllib3/__init__.py", line 8, in <module>
    from .connectionpool import (
  File "/home/chaitu/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 11, in <module>
    from .exceptions import (
  File "/home/chaitu/.local/lib/python3.6/site-packages/urllib3/exceptions.py", line 2, in <module>
    from .packages.six.moves.http_client import (
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 951, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 890, in _find_spec
  File "<frozen importlib._bootstrap>", line 867, in _find_spec_legacy
  File "<frozen importlib._bootstrap>", line 449, in spec_from_loader
  File "/home/chaitu/.local/lib/python3.6/site-packages/urllib3/packages/six.py", line 216, in is_package
    return hasattr(self.__get_module(fullname), "__path__")
  File "/home/chaitu/.local/lib/python3.6/site-packages/urllib3/packages/six.py", line 118, in __getattr__
    _module = self._resolve()
  File "/home/chaitu/.local/lib/python3.6/site-packages/urllib3/packages/six.py", line 115, in _resolve
    return _import_module(self.mod)
  File "/home/chaitu/.local/lib/python3.6/site-packages/urllib3/packages/six.py", line 82, in _import_module
    __import__(name)
  File "/usr/lib/python3.6/http/client.py", line 71, in <module>
    import email.parser
  File "/usr/lib/python3.6/email/parser.py", line 12, in <module>
    from email.feedparser import FeedParser, BytesFeedParser
  File "/usr/lib/python3.6/email/feedparser.py", line 27, in <module>
    from email._policybase import compat32
  File "/usr/lib/python3.6/email/_policybase.py", line 9, in <module>
    from email.utils import _has_surrogates
  File "/usr/lib/python3.6/email/utils.py", line 28, in <module>
    import random
  File "/home/chaitu/random.py", line 3, in <module>
    n=int(input())
ValueError: invalid literal for int() with base 10: ''
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/tempfile.py", line 184, in <module>
    from random import Random as _Random
  File "/home/chaitu/random.py", line 3, in <module>
    n=int(input())
ValueError: invalid literal for int() with base 10: ''

Original exception was:
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 888, in _find_spec
AttributeError: '_SixMetaPathImporter' object has no attribute 'find_spec'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/chaitu/.local/lib/python3.6/site-packages/requests/__init__.py", line 43, in <module>
    import urllib3
  File "/home/chaitu/.local/lib/python3.6/site-packages/urllib3/__init__.py", line 8, in <module>
    from .connectionpool import (
  File "/home/chaitu/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 11, in <module>
    from .exceptions import (
  File "/home/chaitu/.local/lib/python3.6/site-packages/urllib3/exceptions.py", line 2, in <module>
    from .packages.six.moves.http_client import (
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 951, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 890, in _find_spec
  File "<frozen importlib._bootstrap>", line 867, in _find_spec_legacy
  File "<frozen importlib._bootstrap>", line 449, in spec_from_loader
  File "/home/chaitu/.local/lib/python3.6/site-packages/urllib3/packages/six.py", line 216, in is_package
    return hasattr(self.__get_module(fullname), "__path__")
  File "/home/chaitu/.local/lib/python3.6/site-packages/urllib3/packages/six.py", line 118, in __getattr__
    _module = self._resolve()
  File "/home/chaitu/.local/lib/python3.6/site-packages/urllib3/packages/six.py", line 115, in _resolve
    return _import_module(self.mod)
  File "/home/chaitu/.local/lib/python3.6/site-packages/urllib3/packages/six.py", line 82, in _import_module
    __import__(name)
  File "/usr/lib/python3.6/http/client.py", line 71, in <module>
    import email.parser
  File "/usr/lib/python3.6/email/parser.py", line 12, in <module>
    from email.feedparser import FeedParser, BytesFeedParser
  File "/usr/lib/python3.6/email/feedparser.py", line 27, in <module>
    from email._policybase import compat32
  File "/usr/lib/python3.6/email/_policybase.py", line 9, in <module>
    from email.utils import _has_surrogates
  File "/usr/lib/python3.6/email/utils.py", line 28, in <module>
    import random
  File "/home/chaitu/random.py", line 3, in <module>
    n=int(input())
ValueError: invalid literal for int() with base 10: ''

1 个答案:

答案 0 :(得分:1)

您为自己的模块random.py命名了,它正在the built-in random module之下。额外的错误是由错误处理挂钩本身具有错误引起的,但最终是由它们期望内置模块并获取不相关的模块引起的。不要命名内置模块。

您自己的random.py试图做int(input())并似乎失败了,因为它没有从stdin读取任何内容,这似乎是一个进一步的错误,但这是一个相当明显的错误(您输入了什么都没有,或者您以关闭stdin的方式启动了它。)