問題:使用pip3命令安裝robotframework-excellibrary失敗
報錯:execfile(join(dirname(file), ‘ExcelLibrary’, ‘version.py’)) NameError: name ‘execfile’ is not defined
原因:robotframework-excellibrary適用於python2.x版本,不相容python3.x版本
解決
1、離線下載robotframework-excellibrary
下載地址:https://files.pythonhosted.org/packages/b8/e7/8c079a814e7ad288ec2fc15671d8dc526e3d537bb00e4ab2b209a63674ed/robotframework-excellibrary-0.0.2.zip
2、下載的檔案解壓到pthon的site-packages資料夾中
我的地址為:/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
3、robotframework-excellibrary內修改setup.py檔案,開啟檔案“/robotframework-excellibrary-0.0.2/setup.py”
#execfile(join(dirname(__file__), 'ExcelLibrary', 'version.py'))
exec(open(join(dirname(__file__), 'ExcelLibrary', 'version.py')).read())
4、修改/robotframework-excellibrary-0.0.2/ExcelLibrary/ExcelLibrary.py
#from version import VERSION
from .version import VERSION
5、/robotframework-excellibrary-0.0.2/ExcelLibrary/ExcelLibrary.py
將所有的print xxx 語句修改為 print(xxx)
6、修改/robotframework-excellibrary-0.0.2/ExcelLibrary/__init__.py
#from ExcelLibrary import ExcelLibrary
#from version import VERSION
from .ExcelLibrary import ExcelLibrary
from .version import VERSION
7、終端進入資料夾後執行命令離線安裝
python3 setup.py install
8、pip3 list檢視是否安裝成功
9、重啟ride,重新匯入ExcelLibrary
10、提示缺少模組,正常安裝即可
pip3 install natsort
pip3 install xlwt
pip3 install xlutils
11、再次重啟ride,匯入ExcelLibrary成功