I am currently working to upgrade from django 1.3 to 1.8. I have my app working on Ubuntu (Ubuntu 16.04) now however am having problems with the Windows version.
我目前正在努力从django 1.3升级到1.8。我的应用程序现在正在使用Ubuntu(Ubuntu 16.04)但是我遇到了Windows版本的问题。
When I run my custom management commands on Windows the following errors are generated:
当我在Windows上运行自定义管理命令时,会生成以下错误:
Traceback (most recent call last):
File "D:\src\proj\grp\tests\test_list_members.py", line 29, in setUp
call_command('syncgroups')
File "D:\src\env\lib\site-packages\django\core\management\__init__.py", line 103, in call_command
parser = command.create_parser('', name)
File "D:\src\env\lib\site-packages\django\core\management\base.py", line 316, in create_parser
help='Verbosity level; 0=minimal output, 1=normal output, 2=verbose output, 3=very verbose output')
File "C:\Python27\Lib\optparse.py", line 1018, in add_option
raise TypeError, "invalid arguments"
TypeError: invalid arguments
I have managed to locate the source of the issue, it appears that the handling of __future__.unicode_literals
is different on Windows than on Ubuntu. For example the following works on Ubuntu but not on Windows (the same TypeError
error as above is seen)
我已设法找到问题的根源,看来__future __。unicode_literals的处理在Windows上与在Ubuntu上的处理不同。例如,以下适用于Ubuntu但不适用于Windows(与上面相同的TypeError错误)
from __future__ import unicode_literals
from optparse import OptionParser
OptionParser().add_option('-v', '--verbose')
Does this mean that Django 1.8 no longer supports custom management commands on Windows?
这是否意味着Django 1.8不再支持Windows上的自定义管理命令?
Any workarounds would be greatly appreciated!
任何变通办法都将非常感谢!
1 个解决方案
#1
0
The problem was the version of OptionParser installed on my Windows machine had not been updated to support Unicode properly. Updating my python installation was the best solution however a temporary workaround was also possible.
问题是我的Windows机器上安装的OptionParser版本尚未更新以正确支持Unicode。更新我的python安装是最好的解决方案,但也可以使用临时解决方法。
Making the following change to %PYTHONHOME%\Lib\optparse.py resolved this issue...
对%PYTHONHOME%\ Lib \ optparse.py进行以下更改解决了此问题...
1006 ...
1007 def add_option(self, *args, **kwargs):
1008 """add_option(Option)
1009 add_option(opt_str, ..., kwarg=val, ...)
1010 """
+- if type(args[0]) in types.StringTypes:
1012 option = self.option_class(*args, **kwargs)
1013 elif len(args) == 1 and not kwargs:
1014 option = args[0]
1015 ...
#1
0
The problem was the version of OptionParser installed on my Windows machine had not been updated to support Unicode properly. Updating my python installation was the best solution however a temporary workaround was also possible.
问题是我的Windows机器上安装的OptionParser版本尚未更新以正确支持Unicode。更新我的python安装是最好的解决方案,但也可以使用临时解决方法。
Making the following change to %PYTHONHOME%\Lib\optparse.py resolved this issue...
对%PYTHONHOME%\ Lib \ optparse.py进行以下更改解决了此问题...
1006 ...
1007 def add_option(self, *args, **kwargs):
1008 """add_option(Option)
1009 add_option(opt_str, ..., kwarg=val, ...)
1010 """
+- if type(args[0]) in types.StringTypes:
1012 option = self.option_class(*args, **kwargs)
1013 elif len(args) == 1 and not kwargs:
1014 option = args[0]
1015 ...