Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name 'Badge' from 'anybadge' #42

Closed
kagarlickij opened this issue Apr 29, 2020 · 2 comments
Closed

ImportError: cannot import name 'Badge' from 'anybadge' #42

kagarlickij opened this issue Apr 29, 2020 · 2 comments

Comments

@kagarlickij
Copy link

Hi there, I'm trying to use code snippet from README.md:

import anybadge

# Define thresholds: <2=red, <4=orange <8=yellow <10=green
thresholds = {2: 'red',
              4: 'orange',
              6: 'yellow',
              10: 'green'}

badge = anybadge.Badge('pylint', 2.22, thresholds=thresholds)

badge.write_badge('pylint.svg')

And getting ImportError: cannot import name 'Badge' from 'anybadge' error.

Reproduced in both Python 2.7 and 3.7 environments, I used Docker:

FROM python:3.7
RUN apt-get update -y && \
    apt-get install nano -y && \
    pip install anybadge && \
    pip list
COPY . /opt
RUN python /opt/anybadge.py

..and anybadge.py with code above

@jongracecox
Copy link
Owner

jongracecox commented May 20, 2020

I think your issue is that you have a file called anybadge.py, which means, in your code when you run import anybadge you are actually importing your anybadge.py file, and not the anybadge package.

You should be able to fix this by using a different filename (e.g. run_anybadge.py) and then using:

FROM python:3.7
RUN apt-get update -y && \
    apt-get install nano -y && \
    pip install anybadge && \
    pip list
COPY . /opt
RUN python /opt/run_anybadge.py

You could also consider running anybadge as a command rather than in Python, meaning you don't even need the Python module, so something like this:

FROM python:3.7
RUN apt-get update -y && \
    apt-get install nano -y && \
    pip install anybadge && \
    pip list
RUN anybadge --value=2.22 --file=pylint.svg pylint

@kagarlickij
Copy link
Author

Many thanks @jongracecox I should have get another cup of coffee before naming)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants