Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Python 3.4 import error #28

Closed
neviaumi opened this issue Jun 14, 2016 · 9 comments
Closed

Python 3.4 import error #28

neviaumi opened this issue Jun 14, 2016 · 9 comments

Comments

@neviaumi
Copy link

I have installed gflags on python3.4 env.
And after i attempt import gflags it raise "No module named 'cStringIO' "

It should by changed from io import StringIO

Possibly update look like below?

from


gflags/argument_parser.py 
import cStringIO
import csv
import string

to


gflags/argument_parser.py
try: 
     from io import StringIO as cStringIO
except:
     import cStringIO#original code here
import csv
import string

@nickjacobson
Copy link

This pull request: #22 contains code that would fix this issue, and other Python 3 compatibility issues.

@barabo
Copy link

barabo commented Jun 23, 2016

I'm not sure that the above fix completely solves the problem with Python 3+

It does solve the import error, but I believe there are other issues with the argument_parser.CsvListSerializer class (like, unicode doesn't exist in python3 and it's mentioned within the Serialize function.)

class CsvListSerializer(ArgumentSerializer):

  def __init__(self, list_sep):
    self.list_sep = list_sep

  def Serialize(self, value):
    """Serialize a list as a string, if possible, or as a unicode string."""
    output = cStringIO.StringIO()
    writer = csv.writer(output)

    # csv.writer doesn't accept unicode, so we convert to UTF-8.
    encoded_value = [unicode(x).encode('utf-8') for x in value]  ### <- broken in python3
    writer.writerow(encoded_value)

Honestly, looking at the class right above this one - I'm not sure I understand why this wouldn't work instead for either major version of python:

CsvListSerializer = ListSerializer  # Alias class.

I say this because the CsvListSerializer already ignores the list_sep argument and the ListSerializer uses the _helpers.StrOrUnicode function (although, slightly differently) to convert the list values into unicode strings.

Unless I'm missing something, the CsvListSerializer class is basically useless and ListSerializer(',') could be used instead.

This would prevent the need to import cStringIO in this module entirely.

vrusinov added a commit that referenced this issue Jul 17, 2016
It is declares python2-only at the momens since there are still issues with
python3 support.

Related:
 - github pull request #22
 - github pull request #26
 - github pull request #29
 - github issue #28
 - github issue #20

	Change on 2016/06/20 by vrusinov <vrusinov@google.com>

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=125322335
@crutcher
Copy link

Do we have any visibility on timelines here? Would additional work be welcome? I could work on py3 problems, but am unsure if they would be merged; some direction would be useful.

@gpshead
Copy link
Contributor

gpshead commented Sep 16, 2016

It is actively being worked on internally, expect a push for Python 3 compatibility within a month is my best vague estimate (probably sooner but i'm not promising dates).

@sneakywombat
Copy link

@gpshead, anything we can do to help it along?

@gpshead
Copy link
Contributor

gpshead commented Oct 13, 2016

We've got this working internally now; I expect @vrusinov will push the changes later this month.

@mrdrozdov
Copy link

@gpshead any followup on this?

@gpshead
Copy link
Contributor

gpshead commented Nov 15, 2016

@vrusinov pushed an update and a 3.1.0 release earlier this month. give it a try.

@mrdrozdov
Copy link

This is so great! Thank you :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants