How to determine which object is Nonetype and which is str in Python and how do I fix the Concatenate error?

When trying to install pygames to my enthought dome I run setup.py and it always gives "TypeError: cannot concatenate" str "and" Nonetype "objects

TypeError                                 Traceback (most recent call last)
C:\Users\Allie\Canopy\pygame-master\setup.py in <module>()
    145 # get compile info for all extensions
    146 try:
--> 147     extensions = read_setup_file('Setup')
    148 except:
    149     print ("""Error with the "Setup" file,

C:\Users\Allie\AppData\Local\Enthought\Canopy32\App\appdata\canopy-1.5.2.2785.win-x86\lib\distutils\extension.pyc in read_setup_file(filename)
    166 
    167             #print "original line: " + line
--> 168             line = expand_makefile_vars(line, vars)
    169             words = split_quoted(line)
    170             #print "expanded line: " + line

C:\Users\Allie\AppData\Local\Enthought\Canopy32\App\appdata\canopy-1.5.2.2785.win-x86\lib\distutils\sysconfig.pyc in expand_makefile_vars(s, vars)
    407         if m:
    408             (beg, end) = m.span()
--> 409             s = s[0:beg] + vars.get(m.group(1)) + s[end:]
    410         else:
    411             break

TypeError: cannot concatenate 'str' and 'NoneType' objects

      

Can anyone help me fix these lines to get my setup file running? Otherwise, I have no idea how to install pygames in a canopy.

+3


source to share


2 answers


The code is trying to expand the variables in your Makefile, but couldn't find the specific variable.

First, the code parses all records VARNAME = value

, and then in the second step it tries to insert values ​​into links $(VARNAME)

and ${VARNAME}

. It is that the second step, which was not listed as a variable name, was not defined, or at least not found in the first step.



The build system pygame

generates a named make file from a named Setup

file Setup.in

and this is a generated file that doesn't work here. Where Setup.in

has a section marked with #--StartConfig

/ #--EndConfig

, variables should be written. You will have to investigate which lines are missing and why.

You can rerun the config.py

script to re-generate the file; it delegates platform modules to work with.

+2


source


@ageoca, since you asked how to determine the type of None, you can try a simple if statement:

if v != None:
    print(len(v))
else:
    print(-1)

      



Using this, you can develop a strategy for this exception that you are facing.

You can also find a nice little tutorial describing this in a little more detail at dotnetpearls.com -> http://www.dotnetperls.com/none-python

0


source







All Articles