electronicman
Posts: 26
Joined: Mon Dec 10, 2012 9:31 pm
Location: USA

Magpi 51

Fri Dec 16, 2016 12:11 am

As I have a string of LEDs that I am playing with, using some code I cobbled together myself using Python, I thought I would try out the Christmas lights as a bit of fun as shown in the Christmas edition of MagPi.

I tried out all of the various codes but unfortunately I could not get them to work. I have all of the modules shown below but I am at a loss as to why the do not appear to work. Can some one please tell me what I am doing wrong, or am I missing something?



Code: Select all

[email protected]:~ $ sudo python candle_flicker.py
Traceback (most recent call last):
  File "candle_flicker.py", line 2, in <module>
    from gpiozero import PWMLED, LED
  File "/usr/lib/python2.7/dist-packages/gpiozero/__init__.py", line 58, in <module>
    from .devices import (
  File "/usr/lib/python2.7/dist-packages/gpiozero/devices.py", line 18, in <module>
    import pkg_resources
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 34, in <module>
    import email.parser
  File "/usr/lib/python2.7/email/parser.py", line 12, in <module>
    from email.feedparser import FeedParser
  File "/usr/lib/python2.7/email/feedparser.py", line 27, in <module>
    from email import message
  File "/usr/lib/python2.7/email/message.py", line 16, in <module>
    import email.charset
  File "/usr/lib/python2.7/email/charset.py", line 13, in <module>
    import email.base64mime
  File "/usr/lib/python2.7/email/base64mime.py", line 40, in <module>
    from email.utils import fix_eols
  File "/usr/lib/python2.7/email/utils.py", line 27, in <module>
    import random
  File "/home/pi/random.py", line 14, in <module>
    ------------------------------
AttributeError: 'module' object has no attribute 'randint'
[email protected]o-110:~ $ 
David

DirkS
Posts: 9487
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Magpi 51

Fri Dec 16, 2016 12:21 am

The hint is right at the end

Code: Select all

  File "/home/pi/random.py", line 14, in <module>
    ------------------------------
AttributeError: 'module' object has no attribute 'randint'
[email protected]:~ $
You have created a file called 'random.py' in your home directory.
Python wants to open an installed module with the same name, but finds yours first.

Rename the '/home/pi/random.py' and try again.

B.Goode
Posts: 6544
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Magpi 51

Fri Dec 16, 2016 8:12 am

In addition to the correct explanation and fix from @DirkS you probably need to delete the file '/home/pi/random.pyc'

electronicman
Posts: 26
Joined: Mon Dec 10, 2012 9:31 pm
Location: USA

Re: Magpi 51

Fri Dec 16, 2016 6:27 pm

Thank you both of you, it was that simple Duh! It now works as expected.
David

Return to “The MagPi”