我的代码是这样的:
import runpy
runpy.run_path('other.py', globals())它可以在我的Windows Box和Python3.2上运行,但在我的Ubuntu10.10机器上的默认Python3安装(从Repository)上失败,并显示以下消息:
Traceback (most recent call last):
File "/home/markus/Documents/projects/BlenderSerialize/generate.py", line 2, in <module>
runpy.run_path('other.py', globals())
AttributeError: 'module' object has no attribute 'run_path'我查看了文档,发现run_path是在Python2.7中引入的。我要怎么做才能让它工作呢?
发布于 2011-11-23 22:30:04
当不能选择更新Python3时,有一种变通方法可以让用户执行python脚本。
下面的python代码对我来说工作得很好:
exec(compile(open("somefile.py").read(), "somefile.py", 'exec'), local_vars, global_vars)发布于 2011-11-17 19:17:14
它是在Python 2.7和3.2中引入的。因此,它不能与Python 3.0或3.1一起工作。要使其正常工作,请使用Python 2.7或3.2。
https://stackoverflow.com/questions/8163650
复制相似问题