无法导入“progressbar2”库

2024-09-30 20:24:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我是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
}

一开始我面对的问题是我还没有安装库,所以当我安装它并期望一切正常工作时,我得到了新的错误。你知道吗

我使用的是python3.7.0。你知道吗


Tags: and代码importinputdataifareafloat
3条回答

如果你试过

康达安装进度条2

然后进行pip安装

pip安装进度条2

[注意:如果您没有安装“pip”,请通过此链接安装piphttps://www.youtube.com/watch?v=AVCcFyYynQY]

[如果不起作用,则提供更详细的错误消息。]

此模块的名称为progressbar2,编号为2,安装时使用

pip install progressbar2

但在代码中,它使用的名称没有2

import time
import progressbar

for i in progressbar.progressbar(range(100)):
     time.sleep(0.02)

来自documentation的示例

使用 在linux中

$ sudo pip install progressbar2

在windows中,以管理员身份运行cmd并

pip install progressbar2

相关问题 更多 >