簡體   English   中英

AttributeError:“模塊”對象沒有屬性“ maketrans”-PyCharm

[英]AttributeError: 'module' object has no attribute 'maketrans' - PyCharm

我在使用python 2.7 + PyCharm 2016.2 + Windows 10(64)的PC上遇到了這個奇怪的問題。

運行腳本時:

import urllib
from BeautifulSoup import *

url = raw_input('Enter -')
if (len(url) < 1):
    url = "http://python-data.dr-chuck.net/comments_292106.html"
html = urllib.urlopen(url).read()
soup = BeautifulSoup(html)
lst = list()
tags = soup('span')

for tag in tags:
#    print 'TAG:', tag
#    print 'URL:', tag.get('href', None)
#    print 'Contents:', tag.contents
#    print 'Attrs:', tag.attrs
    num = int(tag.contents[0])
    lst.append(num)
print sum(lst)

我收到這樣的消息:

C:\Python27\python.exe E:/python/coursera/following_links.py
23
0.8475
Traceback (most recent call 
  File "E:/python/coursera/following_links.py", line 1, in <module>
    import urllib
  File "C:\Python27\lib\urllib.py", line 30, in <module>
    import base64
  File "C:\Python27\lib\base64.py", line 98, in <module>
    _urlsafe_encode_translation = string.maketrans(b'+/', b'-_')
AttributeError: 'module' object has no attribute 'maketrans'

Process finished with exit code 1

在WingIDE中也會發生相同的情況。

有趣的是,在使用python的Idle時,此腳本有效。

它也可以在裝有Windows 8(64)(Python 2.7和PyCharm 2016.2)的第二台PC上使用

我認為這是在幕后發生的。 為了執行您的命令,Python必須做一些工作,並且沒有找到所需的文件。 這也許可以解釋為什么它可以在Idle和PC上運行,而不在Wing IDE等其他設備上運行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM