【发布时间】:2019-07-11 03:44:59
【问题描述】:
我是 python 的新手,我试图在我的代码中使用 python 库progressbar2。
我尝试使用conda 命令安装该库以确保它已安装在 anaconda 环境中,并且我使用的是 VS 代码并且它也设置在相同的环境中,所以当我尝试在我的代码中导入此库时与:
from progressbar2 import *
mselection = float(input("Method number : "))
while not 1 <= mselection <= 2:
print("Invailed value")
mselection = float(input("Method number : "))
else:
if mselection == 1:
area = float(input("Area: "))
xyratio = float(input("X/Y Ratio: "))
y = (area/xyratio)**(1/2)
x = (area*xyratio)**(1/2)
values = {'x':x,'y':y}
values['o_data'] = [area, xyratio]
print("The hight and weidth needed to create:-\nA rectangle with area {0[o_data][0]:^10}\nThe ratio between them {0[o_data][1]:^10}\nIs({0[x]:^10},{0[y]:^10})\nFor X= higth and Y= weidth.".format(values))
input()
elif mselection == 2:
def result(y=0, i=0, ratio=1):
return print(f"Y= {y:<20} X= {i:<20} Ratio= {xyratio}")
area = float(input("Area: "))
xmin = float(input("Xmin: "))
xmax = float(input("Xmax: "))
step = float(input("Step: "))
include = str(input("Include: "))
i = xmin
pbar = p
widgets = ['Test: ', Percentage(), ' ', Bar(marker='0',left='[',right=']'),
' ', ETA(), ' ', FileTransferSpeed()] #see docs for other options
pbar = ProgressBar(widgets=widgets, maxval=((xmax-xmin)*(1/step)))
pbar.start()
while i <= xmax:
y = area/i
xyratio = str(i/y)
if include in xyratio:
result(y=y,i=i,ratio=xyratio)
i = i + step
pbar.update()
if i == 0:
i = 1
pbar.finish()
input()
我得到这个错误:-
{"resource": "/C:/Users/User/Desktop/Rectangle higth and weidth calculator.py",
"owner": "python",
"code": "import-error",
"severity": 8,
"message": "Unable to import 'progressbar2'",
"source": "pylint",
"startLineNumber": 2,
"startColumn": 1,
"endLineNumber": 2,
"endColumn": 1
}
一开始我遇到的问题是我还没有安装库,所以当我安装它并期望一切正常时,我得到了新的错误。
我正在使用 python 3.7.0。
【问题讨论】:
-
什么新错误?始终将完整的错误消息(从单词“Traceback”开始)放在问题中(作为文本,而不是屏幕截图)。还有其他有用的信息。
-
我添加了完整的错误
-
你可能安装了两个 python。一个安装了模块,第二个运行您的代码。
-
Anaconda 为我安装了所有东西,所有库都在它的环境文件夹中,我没有手动安装任何东西
-
我删除了那行,它工作得很好!非常感谢
标签: python python-3.x progress-bar