AhmedAhmedEG
AhmedAhmedEG

Reputation: 19

Unable to import 'progressbar2' library

I'm a newbie in python, and I was trying to use python library progressbar2 in my code.

I tried installing the library with conda command to make sure it's installed in the anaconda environment, and I'm using VS code and it's set in the same environment too, so when I tried to import this library in my code with:

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()            

I get this error:-

{"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
}

At first I faced the problem where I had not installed the library yet, so when I installed it and expected everything to work correctly, I got new error.

I'm using python 3.7.0.

Upvotes: 0

Views: 2768

Answers (3)

furas
furas

Reputation: 142631

This module has name progressbar2 with number 2 and you install it with

pip install progressbar2

but in code it uses name without 2

import time
import progressbar

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

Example from documentation

Upvotes: 1

Kavindu Ravishka
Kavindu Ravishka

Reputation: 819

use in linux

$ sudo pip install progressbar2

in windows run cmd as admin and

pip install progressbar2

Upvotes: 0

Gaurav Shimpi
Gaurav Shimpi

Reputation: 21

If you've tried

conda install progressbar2

then go for the pip install

pip install progressbar2

[Note: if you don't have "pip" installed then go through this link in order to install pip https://www.youtube.com/watch?v=AVCcFyYynQY ]

[If it doesn't works then provide more detailed error message.]

Upvotes: 0

Related Questions