NameError: global name 'myPars' is not defined

Viewed 45

I need some help because I keep getting this erros:

Traceback (most recent call last):
  File "/home/kostas_ubuntu/HemTools/bin/chromHMM.py", line 173, in <module>
    main()
  File "/home/kostas_ubuntu/HemTools/bin/chromHMM.py", line 100, in main
    args = my_args()
  File "/home/kostas_ubuntu/HemTools/bin/chromHMM.py", line 43, in my_args
    input.add_argument('-bin',"--chromHMM_jar",  help="chromHMM bin location",default=myPars['chromHMM_jar'])
NameError: global name 'myPars' is not defined

I run the script and get this error although in the script I import the utils.py module that sets the myPars variable. The below code snippet comes from the utils.py module.

p_dir = os.path.dirname(os.path.realpath(__file__)) + "/"
username = getpass.getuser()
myData = parse_config(p_dir+"../config/data.config")
myPars = parse_config(p_dir+"../config/parameters.config")

More information of the scripts you can find on the github links below:

utils.py -> https://github.com/YichaoOU/HemTools/blob/master/utils/utils.py

chromHMM.py ->https://github.com/YichaoOU/HemTools/blob/master/bin/chromHMM.py

Thanks in advance!

1 Answers

In Python 3 you should declare on every new scope the global variables it uses. In your case it'd be like the following:

def my_args():
    global myPars, myData
    
    # ... The remaining code


# ...

def main():
    global myData, myPipelines
    
    # ... The remaining code
Related