Question

I'm a total python newbie. I installed python 3.3.1 on a 32 bit windows 7 professional. I'm trying to install RapidSMS, and it should be as easy as "pip install rapidsms" and it does start the process, but it doesn't complete and I'm left with the below error message.

I've been trying to google it, but I haven't been able to find this specific problem, for the error I find fixes for people who have written the code themselves, and I haven't seen anyone mention this problem about rapidsms themselves. Since it stops in Django-tables, I wonder if I messed up that installation somehow or if there's a problem with the python version compatibility. I've used pip when installing some other software, so I don't think that's the problem.

So if anyone's encountered this error when installing pyhton packages or really have any idea what the cause might be I'd really appreciate it! (I also plan to post this in the RapidSMS mailing list when I get approved, but wanted to see if this was a more general problem that might have a fix.)

Downloading/unpacking django-tables2==0.13.0 (from rapidsms)
 Running setup.py egg_info for package django-tables2
Traceback (most recent call last):
  File "<string>", line 16, in <module>
  File "c:\users\mhealth1\appdata\local\temp\pip-build-mhealth1\django-tables2\setup.py", line 7, in <module>
    version = re.search('__version__ = "(.+?)"', f.read()).group(1)
  File "C:\Python33\lib\re.py", line 161, in search
    return _compile(pattern, flags).search(string)
TypeError: can't use a string pattern on a bytes-like object
    Complete output from command python setup.py egg_info: 
    Traceback (most recent call last):

  File "<string>", line 16, in <module>

  File "c:\users\mhealth1\appdata\local\temp\pip-build-mhealth1\django-tables2\setup.py", line 7, in <module>

    version = re.search('__version__ = "(.+?)"', f.read()).group(1)

  File "C:\Python33\lib\re.py", line 161, in search

    return _compile(pattern, flags).search(string)

TypeError: can't use a string pattern on a bytes-like object

----------------------------------------
Command python setup.py egg_info failed with error code 1 in c:\users\mhealth1\a
ppdata\local\temp\pip-build-mhealth1\django-tables2
Storing complete log in C:\Users\mhealth1\pip\pip.log
Was it helpful?

Solution

Django-tables2 fails to install in Python3 because of the following code from line 7 of setup.py in the traceback:

version = re.search('__version__ = "(.+?)"', f.read()).group(1)

This should work if the search pattern was a bytes object. A byte literal can be created by simply pre-pending the string literal with a b like the following:

version = re.search(b'__version__ = "(.+?)"', f.read()).group(1)

This is why Python is throwing a TypeError with the message "Can't use a string pattern on a bytes-like object". The file contents are being read in as bytes.

I don't think RapidSMS currently supports Python3 yet based on its list of environments that are tested. This can be seen in the tox environments list of the project seen here, in which only Python 2.6 and 2.7 are listed: https://github.com/rapidsms/rapidsms/blob/develop/tox.ini#L2

To solve the immediate problem, you'll want to install RapidSMS in a virtual environment with Python 2.6 or 2.7. The documentation for RapidSMS describes virtual environment setup briefly here: http://www.rapidsms.org/en/develop/topics/virtualenv.html

You'll want to install Python 2.6 or 2.7 on your system and specify which Python for the virtualenv to use, using the -p or --python argument. The following is taken from the RapidSMS docs linked above, but ammended to specify using Python 2.7:

mkvirtualenv --distribute --no-site-packages rapidsms --python=python2.7
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top