无法导入“ progressbar2”库

时间:2019-07-11 03:44:59

标签: python python-3.x progress-bar

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

3 个答案:

答案 0 :(得分:0)

如果您尝试过

conda安装进度栏2

然后去安装pip

pip安装进度栏2

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

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

答案 1 :(得分:0)

使用 在Linux中

$ sudo pip install progressbar2

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

pip install progressbar2

答案 2 :(得分:0)

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

pip install progressbar2

但是在代码中,它使用的名称不带2

import time
import progressbar

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

来自documentation

的示例