Python2 to Python3

1,生成git patch

2to3-3.6 ~/pythondir >> a.patch

2,apply

git apply --stat a_file.patch
git apply --ignore-space-change --ignore-whitespace /Users/kylefan/hobotrl/a.patch

3安装cv2
https://www.codingforentrepreneurs.com/blog/install-opencv-3-for-python-on-mac/

改动:(source–>2to3 auto generation–>correct )
参考:http://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html

xrange统一都变成range了

23中的zip也不一样了,
veloc = np.array(zip(speeds_x, speeds_y))
改为
veloc = list(zip(speeds_x, speeds_y))


reduction.py-line18: 
from cPickle import loads-->from pickle import loads-->from cPickle import loads

exp_atari.py-line18:
from exp_algorithms import *-->from .exp_algorithms import *-->from exp_algorithms import *
(No module named '__main__.exp_algorithms'; '__main__' is not a package)

async.py-line36:
cluster = eval(cluster_spec) #none => SyntaxError: unexpected EOF while parsing
eval(str)将str看作参与计算的python表达式参与求值运算返回计算结果
这个错误是由于cluster.sh中有个python2的print函数:
cluster=$(python -c "import sys;_,port,worker=sys.argv;print \"{'ps':['localhost:\"+port+\"'], 'worker':[\" + \",\".join([\"'localhost:\"+str(i+int(port)+1)+\"'\" for i in range(int(worker))])+\"]}\"" $start_port $worker_n)
将其改为python3的print()即可:
cluster=$(python -c "import sys;_,port,worker=sys.argv;print(\"{'ps':['localhost:\"+port+\"'], 'worker':[\" + \",\".join([\"'localhost:\"+str(i+int(port)+1)+\"'\" for i in range(int(worker))])+\"]}\")" $start_port $worker_n)

playback.py:line304:
step = (self.count / batch_size) --> step = (self.count // batch_size)
这个会导致playback.py line320出现list索引为浮点数的错误

exp_deeprl.py中的
sys.path.append(".")要放在最上面

exp_deeprl.py-line13:
from exp_algorithms import *-->from .exp_algorithms import *-->from exp_algorithms import *

exp_deeprl.py-line15:
import exp_algorithms as alg-->from . import exp_algorithms as alg-->import exp_algorithms as alg

未完待续:
这样修改完后的Python3代码可以执行,但是在pycharm里不是很友好,pycharm会报很多错误,比如很多符号的转到定义操作无法实现

解决:选中上层文件夹,Mark Directory as --> source root
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值