啊,这个故事还是得从Torch深度学习的那个教程开始说起...
因为在参考的其中一篇论文里面看到论文作者使用的是torch7这个框架来跑神经网络,所以本菜鸡也就屁颠屁颠地跑过去,跟人家大大用一样的环境。装好环境就打算按官网教程跑一遍,本来一切都还挺顺利的,在跑到教程的显示图片那段代码中就开始出问题了。就是下面这段
itorch.image(trainset.data[100]) -- display the 100-th image in dataset
print(classes[trainset.label[100]])
本人是在sublime text上面跑的,现在忘记报什么错了,反正就是看到网上有人说这个要在notebook上跑,然后就跑去装notebook。macos自带的是python2.7,因此安装命令是
python -m pip install jupyter --user
安装成功之后运行jupyter notebook就报错:UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 4: ordinal not in range(128)
详情如下:
Traceback (most recent call last):
File "/Users/haroroda/Library/Python/2.7/bin/ipython", line 11, in
sys.exit(start_ipython())
File "/Users/haroroda/Library/Python/2.7/lib/python/site-packages/IPython/__init__.py", line 119, in start_ipython
return launch_new_instance(argv=argv, **kwargs)
File "/Users/haroroda/Library/Python/2.7/lib/python/site-packages/traitlets/config/application.py", line 657, in launch_instance
app.initialize(argv)
File "", line 2, in initialize
File "/Users/haroroda/Library/Python/2.7/lib/python/site-packages/traitlets/config/application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "/Users/haroroda/Library/Python/2.7/lib/python/site-packages/IPython/terminal/ipapp.py", line 307, in initialize
super(TerminalIPythonApp, self).initialize(argv)
File "", line 2, in initialize
File "/Users/haroroda/Library/Python/2.7/lib/python/site-packages/traitlets/config/application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "/Users/haroroda/Library/Python/2.7/lib/python/site-packages/IPython/core/application.py", line 455, in initialize
self.parse_command_line(argv)
File "/Users/haroroda/Library/Python/2.7/lib/python/site-packages/IPython/terminal/ipapp.py", line 302, in parse_command_line
return super(TerminalIPythonApp, self).parse_command_line(argv)
File "", line 2, in parse_command_line
File "/Users/haroroda/Library/Python/2.7/lib/python/site-packages/traitlets/config/application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "/Users/haroroda/Library/Python/2.7/lib/python/site-packages/traitlets/config/application.py", line 514, in parse_command_line
return self.initialize_subcommand(subc, subargv)
File "/Users/haroroda/Library/Python/2.7/lib/python/site-packages/IPython/core/application.py", line 244, in initialize_subcommand
return super(BaseIPythonApplication, self).initialize_subcommand(subc, argv)
File "", line 2, in initialize_subcommand
File "/Users/haroroda/Library/Python/2.7/lib/python/site-packages/traitlets/config/application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "/Users/haroroda/Library/Python/2.7/lib/python/site-packages/traitlets/config/application.py", line 452, in initialize_subcommand
self.subapp.initialize(argv)
File "", line 2, in initialize
File "/Users/haroroda/Library/Python/2.7/lib/python/site-packages/traitlets/config/application.py", line 89, in catch_config_error
app.print_help()
File "/Users/haroroda/Library/Python/2.7/lib/python/site-packages/traitlets/config/application.py", line 385, in print_help
self.print_subcommands()
File "/Users/haroroda/Library/Python/2.7/lib/python/site-packages/traitlets/config/application.py", line 377, in print_subcommands
print(os.linesep.join(lines))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 4: ordinal not in range(128)
重头戏来了,关于这个报错我搜了一圈,好几个人都说这是python2.7带的bug,换成python3就好了。大佬都这么说了还能怎么办,只能装python3呗。一顿折腾把python3装好了,默认的python版本也换成3.7了。这时候运行jupyter notebook没报错,成功运行了。心里正美滋滋呢,接着跑去装iTorch。按官网的安装成功后运行itorch,报错
Unsupported ipython version. Only major versions 2.xx, 3.xx, 4.xx or 5.xx (Jupyter) are supported
一看ipython的版本是7.xx。用python3装的jupyter自带ipython7.xx,用python2装的jupyter带的是ipython5.xx。(本人试过单独下载ipython5.3.0的版本,忘记是哪步出错了反正也是不行)
到这里各位都看明白了把,要成功运行jupyter就不能用python2,只能用python3;但要跑通iTorch就不能使用python3,只支持python2,感觉进入了死循环了。正在本菜鸡愁眉不展的时候看到一个大大说,在运行的时候指定语言就好了。原文地址:https://www.jianshu.com/p/516eb2a57ee6
LANG=zn jupyter notebook
这样就可以在python2的环境下顺利运行jupyter,同理,运行itorch notebook命令如下:
LANG=zn itorch notebook