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

UnboundLocalError: local variable 'available_ports' referenced before assignment #43

Closed
farvardin opened this issue Apr 24, 2024 · 11 comments
Assignees
Labels
bug Something isn't working

Comments

@farvardin
Copy link

hello,
i'm using Python 3.10.12 on linux (mint 21.3) and I've setup the venv environement according to the manual there https://github.com/zuggamasta/midiTracker/wiki/01-Installing-midiTracker-(Beginner-Friendly)

after starting miditracker with python3 midiTracker.py, I saw the logo moving to the left, and then it crashed saying:

Traceback (most recent call last):
  File "/temp/github/music/midiTracker/midiTracker.py", line 994, in <module>
    wrapper(main)
  File "/usr/lib/python3.10/curses/__init__.py", line 94, in wrapper
    return func(stdscr, *args, **kwds)
  File "/temp/github/music/midiTracker/midiTracker.py", line 981, in main
    if not current_screen == 4: draw_info(info_win,available_ports[MIDI_PORT])        
UnboundLocalError: local variable 'available_ports' referenced before assignment
@zuggamasta
Copy link
Owner

This is due to some issue in one of the modules I use. You did everything right, but for now version 3.9.xx is required. Im sorry for that inconvenience. I'll hopefully be able to fix this in the next weeks.

I was struggling with that exact same error for weeks.

@zuggamasta zuggamasta added the bug Something isn't working label Apr 24, 2024
@zuggamasta zuggamasta pinned this issue Apr 24, 2024
@estufilla
Copy link

estufilla commented Apr 30, 2024

Happens the same to me on 3.9.10. Weird.

(midiTracker) estufa@uConsole:~/gits/midiTracker $ python3 midiTracker.py Traceback (most recent call last): File "/home/estufa/gits/midiTracker/midiTracker.py", line 994, in <module> wrapper(main) File "/home/estufa/.pyenv/versions/3.9.10/lib/python3.9/curses/__init__.py", line 94, in wrapper return func(stdscr, *args, **kwds) File "/home/estufa/gits/midiTracker/midiTracker.py", line 981, in main if not current_screen == 4: draw_info(info_win,available_ports[MIDI_PORT]) UnboundLocalError: local variable 'available_ports' referenced before assignment (midiTracker) estufa@uConsole:~/gits/midiTracker $ python3 -V Python 3.9.10

@zuggamasta
Copy link
Owner

zuggamasta commented Apr 30, 2024

Oh gosh. Sorry that you both had to encounter that issue.

Thank you for trying out 3.9.10 and reporting. I'll let you know as soon as I figure out more.

@zuggamasta zuggamasta self-assigned this Apr 30, 2024
@estufilla
Copy link

estufilla commented Apr 30, 2024 via email

@estufilla
Copy link

estufilla commented May 1, 2024

Hey!

Hi Zugga and farva, sorry for the double post, but I was on the move on the other one so I couldn't explain myself properly.

I didn't give a lot of info on my system, which shouldn't matter with python as I understand (sorry, I saw my first terminal like 2 months ago, I'm trying hard haha). It's an uConsole with CM4 module (RPi4 basically), running Debian. I already had previously Python 3.11 installed, and used pyenv to get 3.9.10 (as I saw somewhere was the version you used). It didn't work so I downloaded the 3.9 source and compiled with the proper libs. Didn't work either. I have Manjaro in my PC with 3.11 from beforehand, and happened the same.

As I can simply swap microSD and get another system, I'll install arch from scratch and get Python 3.9.10 clean, and try again to see what happens.

I'll report back!

@estufilla
Copy link

estufilla commented May 1, 2024

I tried in 4 different machines. The uConsole, my main PC, my father's PC, and basically 1 Debian chroot and 1 Arch chroot on my Android device. Nothing worked, all 3.9.10, same error.

I did manage to get something different in my main machine. Still, 3.9.10, no idea what I've done here.

   ~/gits/midiTracker    main ?2  python3 midiTracker.py                                                                                                                                                      1 ✘  tracker 3.9.10  
Traceback (most recent call last):
  File "/home/estufa/gits/midiTracker/midiTracker.py", line 994, in <module>
    wrapper(main)
  File "/home/estufa/.pyenv/versions/3.9.10/lib/python3.9/curses/__init__.py", line 94, in wrapper
    return func(stdscr, *args, **kwds)
  File "/home/estufa/gits/midiTracker/midiTracker.py", line 988, in main
    play_song(0)
  File "/home/estufa/gits/midiTracker/midiTracker.py", line 534, in play_song
    play_notes(current_notes_buffer,current_modifier_buffer,current_cc_buffer)
  File "/home/estufa/gits/midiTracker/midiTracker.py", line 610, in play_notes
    outport.send(Message('note_on', channel=channel, note=notes[channel], velocity=120))
AttributeError: 'NoneType' object has no attribute 'send'

Note: git status changed as I added a pyenv version on folder.

EDIT: How can I format this properly? So noob sorry! It literally hurts to try and read lmao.
EDIT2: Sorry won't edit anymore, don't want to be giving false alarms here (idk if it gives notifs). If anyone can point me to the right direction... I can start it, but can't tell to stop it XD
EDIT3: Yep, sorry, got it. Nothing to se here. :)

@zuggamasta
Copy link
Owner

Thank you again for trying this out. I have a bad feeling there might be a step missing in my manual. I now have the time to do new first time installs myself. I'll let you know how it goes.

@estufilla
Copy link

estufilla commented May 2, 2024 via email

@zuggamasta
Copy link
Owner

No need to try the releases. Cloning the git is a good way to stay on track. I figured something out: You'll need to create a new venv for that, writing very verbose to make myself aware of any issues, too:

  1. git clone https://github.com/zuggamasta/midiTracker.git
  2. cd midiTracker/
  3. python3 -m venv venv/ <-- or use your python3.10
  4. source venv/bin/activate
  5. python -V --> verifying that we're in the venv and using the correct version Python 3.10.13 in my case
  6. python -m pip install mido
  7. python -m pip install python-rtmidi
  8. python midiTracker.py

Somehow my first setups all involved both versions of rtmidi, but I ran like this and I got the exact error message as soon as I also installed the "rtmidi" package as noted in my install notes. I now removed that step from the notes.

I hope this gets you started!

@estufilla
Copy link

2024-05-02-14-13-49-776

You're a beast. Now to try and figure out how to resize this xD

@zuggamasta
Copy link
Owner

If it's behaving like a regular raspberryPi, quoting my own forum post :

Go in and use one of the shipped fonts. After selecting one you will get to select the size from a list of options. These sizes will vary from font to font. It might be possible to load custom fonts, but I yet have to find one that is a suitable bitmap font. https://www.raspberrypi-spy.co.uk/2014/ ... font-size/

Closing this ticket for now. Feel free to open a new one any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants