New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with unicode module names on Python2 #9

brutus opened this Issue Jul 4, 2016 · 5 comments


None yet
2 participants

brutus commented Jul 4, 2016

I maintain a Django installation and want to migrate the settings (lots of from X import *) to django-split-setings. Seems everything went fine, but the tox test for Python 2.7 (the only tested version < 3) bailed on me with the following error:

Traceback (most recent call last):
  File ".tox/py27/bin/", line 5, in <module>
  File "/home/…/source/.tox/py27/local/lib/python2.7/site-packages/django/core/management/", line 353, in execute_from_command_line
  File "/home/…/source/.tox/py27/local/lib/python2.7/site-packages/django/core/management/", line 302, in execute
  File "/home/…/source/.tox/py27/local/lib/python2.7/site-packages/django/conf/", line 55, in __getattr__
  File "/home/…/source/.tox/py27/local/lib/python2.7/site-packages/django/conf/", line 43, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/…/source/.tox/py27/local/lib/python2.7/site-packages/django/conf/", line 99, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python2.7/importlib/", line 37, in import_module
  File "/home/…/source/streambox/streambox/settings/", line 19, in <module>
  File "/home/…/source/.tox/py27/local/lib/python2.7/site-packages/split_settings/", line 84, in include
    exec(compile(, included_file, 'exec'), scope)
  File "/home/…/source/streambox/streambox/settings/components/", line 147, in <module>
  File "/home/…/source/.tox/py27/local/lib/python2.7/site-packages/split_settings/", line 90, in include
    module = types.ModuleType(module_name)
TypeError: module.__init__() argument 1 must be string, not unicode

This might be a result of from __future__ import unicode_literals. Any ideas how to handle this?


This comment has been minimized.


sobolevn commented Jul 5, 2016

Thanks, will dig it soon. Do you have any fix for yourself?


This comment has been minimized.

brutus commented Jul 5, 2016

Not really… For starters we just dropped Python 2 support (cause it's not needed in house). But that's temporary, cause we would like to keep 2.7 supported. I'm not sure, if unicode_literals is absolutely needed, but have to read up on it and check our code a lot more.

So, just workarounds for now. I was thinking about monkey–patching and "byteify" the relevant parts… but not sure where to start and what's relevant.

@sobolevn sobolevn added the bug label Jul 5, 2016

@sobolevn sobolevn self-assigned this Jul 5, 2016

@sobolevn sobolevn closed this in d3d1afb Jul 8, 2016


This comment has been minimized.


sobolevn commented Jul 8, 2016

Hi, I got this working. Damn this unicode/str things in python2.

Here's the change itself:

module = types.ModuleType(str(module_name))

It won't probably work on decode error, but that's intended.

This is your example, I guess:

Basic unicode test:


This comment has been minimized.

brutus commented Jul 14, 2016

Thanks for the fast fix!

While we will wait with re–enabling Python 2 support for your next release, I ran the latest Github version in some test environments and it works.


This comment has been minimized.


sobolevn commented Jul 14, 2016

Nice, I will release it soon.

sobolevn added a commit that referenced this issue Jul 14, 2016

Version 0.2.2 release
* Now supporting `unicode` filenames, fixes #9
* Tests structure is changed
* Removed example
* Changed how `` is defined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment