# UnboundLocalError: local variable 'qmax' referenced before assignment

**URL:** <https://forum.biobakery.org/t/unboundlocalerror-local-variable-qmax-referenced-before-assignment/2969>\
**Category:** bioBakery workflows\
**Created:** [January 4, 2022, 11:52pm UTC](https://forum.biobakery.org/t/unboundlocalerror-local-variable-qmax-referenced-before-assignment/2969 "2022-01-04T23:52:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kennyyeo13](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/kennyyeo13/32/1171_2.png) [@kennyyeo13](https://forum.biobakery.org/u/kennyyeo13)\
**Post date:** [January 4, 2022, 11:52pm UTC](https://forum.biobakery.org/t/unboundlocalerror-local-variable-qmax-referenced-before-assignment/2969/1 "2022-01-04T23:52:46Z")

</div>

Hi,

Does anyone know how to solve this problem?

kennyyeo@Kennys-Mac-mini biobakery\_workflows\_databases % biobakery\_workflows 16s --method usearch --usearch-db /Users/kennyyeo/biobakery\_workflows\_databases/green\_genes\_fasta\_db/97\_otus.fasta,/Users/kennyyeo/biobakery\_workflows\_databases/green\_genes\_taxonomy\_db/97\_otu\_taxonomy.txt --input-extension fastq.gz --input /Volumes/Expansion/hnsc\_microbiome\_online/16S\_analysis/PRJNA352375/fastq\_16s --fwd-primer AGAGTTTGATYMTGGCTCAG --rev-primer GWATTACCGCGGCKGCTG --output /Volumes/Expansion/hnsc\_microbiome\_online/16S\_analysis/PRJNA352375/output --threads 6  
Traceback (most recent call last):  
File “/Users/kennyyeo/miniconda3/envs/picrust1/bin/16s.py”, line 165, in   
workflow, args.method, all\_samples\_fastq, args.output, args.threads, args.maxee, args.trunc\_len\_max, args.fastq\_ascii)  
File “/Users/kennyyeo/miniconda3/envs/picrust1/lib/python2.7/site-packages/biobakery\_workflows/tasks/sixteen\_s.py”, line 58, in quality\_control  
qc\_report = quality\_report(workflow, method, fastq\_file, output\_folder, threads, qmax)  
UnboundLocalError: local variable ‘qmax’ referenced before assignment

---

<div class="post-metadata">

**Author:** ![lauren.j.mciver](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@lauren.j.mciver](https://forum.biobakery.org/u/lauren.j.mciver)\
**Post date:** [February 11, 2022, 10:33pm UTC](https://forum.biobakery.org/t/unboundlocalerror-local-variable-qmax-referenced-before-assignment/2969/2 "2022-02-11T22:33:55Z")

</div>

Hello, If you would update to the latest version of the workflows it should resolve the qmax reference issue.

Thank you,  
Lauren

---

<div class="post-metadata">

**Author:** ![sambutle](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@sambutle](https://forum.biobakery.org/u/sambutle)\
**Post date:** [September 6, 2022, 4:25pm UTC](https://forum.biobakery.org/t/unboundlocalerror-local-variable-qmax-referenced-before-assignment/2969/3 "2022-09-06T16:25:11Z")

</div>

> [@kennyyeo13](#):
>
> UnboundLocalError: local variable ‘qmax’ referenced before assignment

An UnboundLocalError is raised when a local variable is referenced before it has been assigned. In most cases this will occur when trying to modify a local variable before it is actually assigned within the local scope. Python doesn’t have variable declarations, so it has to figure out the scope of variables itself. It does so by a simple rule: If there is an assignment to a variable inside a function, that variable is considered local.

Python has lexical scoping by default, which means that although an enclosed scope can access values in its enclosing scope, it cannot modify them (unless they’re declared global with the global keyword). A closure binds values in the enclosing environment to names in the local environment. The local environment can then use the bound value, and even reassign that name to something else, but it can’t modify the binding in the enclosing environment. UnboundLocalError happend because when python sees an assignment inside a function then it considers that variable as local variable and will not fetch its value from enclosing or global scope when we execute the function. However, to modify a [global variable](http://net-informations.com/python/iq/global.htm) inside a function, you must use the global keyword.
