Home >  > Python错误信息大全

Python错误信息大全

0

一、AttributeError: module 'pandas' has no attribute 'read_excel'

你肯定除了原始的pandas,还自己建了个pandas的文件(也可能是csv.py,excel.py之类的名字,统统重命名,这个龟孙bug折腾我搜了老久)

二、TypeError: can't multiply sequence by non-int of type 'float'

代码如下:

x = 100
y = 0
for i in range(0,10):
    x = round(x/2,2)
    y = y + x

print("第10次反弹的高度是%f" % x)
print("总共经过的长度是",3*y)
print("总共经过的长度是%f" % 3*y)

第2个print打印正常,第三个print出现了上面的出错信息。

给分析,原来是后面的3*y没有加括号的原因,由于没有加括号,使得%发生了作用,程序以为要用%来处理后面的3*y,导致出错,解决方法是将最后一句改成:

print("总共经过的米数是%.2f" % (3*y))

三、今天在运行网上copy过来的一段代码的时候,出现了如下的错误提示:
from collections import namedtuple
ImportError: cannot import name 'namedtuple'

经查资料知道,collections是Python内建的一个集合模块,提供了许多有用的集合类。namedtuple是一个函数,它用来创建一个自定义的tuple对象,并且规定了tuple元素的个数,并可以用属性而不是索引来引用tuple的某个元素。

在stackoverflow看到有人在提同样的问题,其中有人回复到:

Also, have you somehow gotten C:\Python27\Lib\site-packages\openpyxl to your sys.path? If so, that's the problem. (Never add a package directory itself to your path.)

我看了一下我的sys.path,发现也加入了其他package directory。
Snap61

正想着如何删除这个路径的时候,又看到有人这样说:

上网查了资料才发现,是因为在运行python脚本的目录下,是不允许有.pyc文件,

把目录下的.pyc文件移除,即可解决

我找了一下,这个目录下,没看到有.pyc文件,不过我将这段代码放到另外一个文件夹下面运行,就成功了。

四、虚拟环境报错
今天在本地电脑上使用virtualenv创建虚拟环境也报错。折腾了一番,发现应该是伟大墙的问题。
报错信息如下,如果你遇到同样的问题,可以释怀了。

Using base prefix 'c:\\programdata\\anaconda3'
  No LICENSE.txt / LICENSE found in source
New python executable in H:\web\keywords\keywordsWebenv\Scripts\python.exe
Installing setuptools, pip, wheel...

  Complete output from command H:\web\keywords\keyw...v\Scripts\python.exe - se
uptools pip wheel:
  Looking in links: c:\programdata\anaconda3\lib\site-packages\virtualenv_suppo
t
Collecting setuptools
Collecting pip
  Downloading https://files.pythonhosted.org/packages/54/0c/d01aa759fdc501a58f4
1eb594a17495f15b88da142ce14b5845662c13f3/pip-20.0.2-py2.py3-none-any.whl (1.4MB

ERROR: Exception:
Traceback (most recent call last):
  File "c:\programdata\anaconda3\lib\site-packages\virtualenv_support\pip-19.1-
y2.py3-none-any.whl\pip\_vendor\urllib3\response.py", line 360, in _error_catch
r
    yield
  File "c:\programdata\anaconda3\lib\site-packages\virtualenv_support\pip-19.1-
y2.py3-none-any.whl\pip\_vendor\urllib3\response.py", line 442, in read
    data = self._fp.read(amt)
  File "c:\programdata\anaconda3\lib\site-packages\virtualenv_support\pip-19.1-
y2.py3-none-any.whl\pip\_vendor\cachecontrol\filewrapper.py", line 62, in read
    data = self.__fp.read(amt)
  File "c:\programdata\anaconda3\Lib\http\client.py", line 449, in read
    n = self.readinto(b)
  File "c:\programdata\anaconda3\Lib\http\client.py", line 493, in readinto
    n = self.fp.readinto(b)
  File "c:\programdata\anaconda3\Lib\socket.py", line 586, in readinto
    return self._sock.recv_into(b)
  File "c:\programdata\anaconda3\Lib\ssl.py", line 1009, in recv_into
    return self.read(nbytes, buffer)
  File "c:\programdata\anaconda3\Lib\ssl.py", line 871, in read
    return self._sslobj.read(len, buffer)
  File "c:\programdata\anaconda3\Lib\ssl.py", line 631, in read
    v = self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\programdata\anaconda3\lib\site-packages\virtualenv_support\pip-19.1-
y2.py3-none-any.whl\pip\_internal\cli\base_command.py", line 178, in main
    status = self.run(options, args)
  File "c:\programdata\anaconda3\lib\site-packages\virtualenv_support\pip-19.1-
y2.py3-none-any.whl\pip\_internal\commands\install.py", line 352, in run
    resolver.resolve(requirement_set)
  File "c:\programdata\anaconda3\lib\site-packages\virtualenv_support\pip-19.1-
y2.py3-none-any.whl\pip\_internal\resolve.py", line 131, in resolve
    self._resolve_one(requirement_set, req)
  File "c:\programdata\anaconda3\lib\site-packages\virtualenv_support\pip-19.1-
y2.py3-none-any.whl\pip\_internal\resolve.py", line 294, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "c:\programdata\anaconda3\lib\site-packages\virtualenv_support\pip-19.1-
y2.py3-none-any.whl\pip\_internal\resolve.py", line 242, in _get_abstract_dist_
or
    self.require_hashes
  File "c:\programdata\anaconda3\lib\site-packages\virtualenv_support\pip-19.1-
y2.py3-none-any.whl\pip\_internal\operations\prepare.py", line 353, in prepare_
inked_requirement
    progress_bar=self.progress_bar
  File "c:\programdata\anaconda3\lib\site-packages\virtualenv_support\pip-19.1-
y2.py3-none-any.whl\pip\_internal\download.py", line 886, in unpack_url
    progress_bar=progress_bar
  File "c:\programdata\anaconda3\lib\site-packages\virtualenv_support\pip-19.1-
y2.py3-none-any.whl\pip\_internal\download.py", line 746, in unpack_http_url
    progress_bar)
  File "c:\programdata\anaconda3\lib\site-packages\virtualenv_support\pip-19.1-
y2.py3-none-any.whl\pip\_internal\download.py", line 954, in _download_http_url
    _download_url(resp, link, content_file, hashes, progress_bar)
  File "c:\programdata\anaconda3\lib\site-packages\virtualenv_support\pip-19.1-
y2.py3-none-any.whl\pip\_internal\download.py", line 683, in _download_url
    hashes.check_against_chunks(downloaded_chunks)
  File "c:\programdata\anaconda3\lib\site-packages\virtualenv_support\pip-19.1-
y2.py3-none-any.whl\pip\_internal\utils\hashes.py", line 62, in check_against_c
unks
    for chunk in chunks:
  File "c:\programdata\anaconda3\lib\site-packages\virtualenv_support\pip-19.1-
y2.py3-none-any.whl\pip\_internal\download.py", line 651, in written_chunks
    for chunk in chunks:
  File "c:\programdata\anaconda3\lib\site-packages\virtualenv_support\pip-19.1-
y2.py3-none-any.whl\pip\_internal\utils\ui.py", line 156, in iter
    for x in it:
  File "c:\programdata\anaconda3\lib\site-packages\virtualenv_support\pip-19.1-
y2.py3-none-any.whl\pip\_internal\download.py", line 640, in resp_read
    decode_content=False):
  File "c:\programdata\anaconda3\lib\site-packages\virtualenv_support\pip-19.1-
y2.py3-none-any.whl\pip\_vendor\urllib3\response.py", line 494, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "c:\programdata\anaconda3\lib\site-packages\virtualenv_support\pip-19.1-
y2.py3-none-any.whl\pip\_vendor\urllib3\response.py", line 459, in read
    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  File "c:\programdata\anaconda3\Lib\contextlib.py", line 99, in __exit__
    self.gen.throw(type, value, traceback)
  File "c:\programdata\anaconda3\lib\site-packages\virtualenv_support\pip-19.1-
y2.py3-none-any.whl\pip\_vendor\urllib3\response.py", line 365, in _error_catch
r
    raise ReadTimeoutError(self._pool, None, 'Read timed out.')
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='file
.pythonhosted.org', port=443): Read timed out.
----------------------------------------
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
  File "c:\programdata\anaconda3\lib\runpy.py", line 193, in _run_module_as_mai

    "__main__", mod_spec)
  File "c:\programdata\anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\ProgramData\Anaconda3\Scripts\virtualenv.exe\__main__.py", line 9, i
 <module>
  File "c:\programdata\anaconda3\lib\site-packages\virtualenv.py", line 834, in
main
    symlink=options.symlink,
  File "c:\programdata\anaconda3\lib\site-packages\virtualenv.py", line 1129, i
 create_environment
    install_wheel(to_install, py_executable, search_dirs, download=download)
  File "c:\programdata\anaconda3\lib\site-packages\virtualenv.py", line 976, in
install_wheel
    _install_wheel_with_search_dir(download, project_names, py_executable, sear
h_dirs)
  File "c:\programdata\anaconda3\lib\site-packages\virtualenv.py", line 1066, i
 _install_wheel_with_search_dir
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=script)
  File "c:\programdata\anaconda3\lib\site-packages\virtualenv.py", line 927, in
call_subprocess
    raise OSError("Command {} failed with error code {}".format(cmd_desc, proc.
eturncode))
OSError: Command H:\web\keywords\keyw...v\Scripts\python.exe - setuptools pip w
eel failed with error code 2

H:\web\keywords>
本文暂无标签

发表评论

*

*