自动化测试工具 关于 Mac 10.12.3 无法安装 robotframework 问题请教

骨头骨头懒骨头 · 2017年03月15日 · 最后由 骨头骨头懒骨头 回复于 2017年03月16日 · 3622 次阅读

如何在Mac os x 10.12.3上安装 robotframework,最近折腾了几天也没搞定。网上该找的文档也基本看了遍未能解决,特来请教。
相关依赖已经通过 pip 安装上了。
pip freeze
robotframework==3.0.2
robotframework-ride==1.5.2.1
wxPython-common==2.8.12.1

执行 ride.py 还是提示未找到 wxPython,但单独进 python 里面 import wx 也是正常的:

python
Python 2.7.10 (default, Jul 30 2016, 19:40:32) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> wx
<module 'wx' from '/usr/local/lib/wxPython-unicode-2.8.12.1/lib/python2.7/site-packages/wx-2.8-mac-unicode/wx/__init__.pyc'>
>>> 

ride.py 
wxPython not found.
You need to install wxPython 2.8.12.1 or 3.0.2 or newer with unicode support to run RIDE. wxPython can be downloaded from http://sourceforge.net/projects/wxpython/files/wxPython/

单独执行 pybot --help,也报错,去 python 命令行里执行这个 import 确实不行:

Traceback (most recent call last):
  File "/usr/local/bin/pybot", line 4, in <module>
    from robot import run_cli
ImportError: cannot import name run_cli

虽然 Mac 自带的 python 是 64bit 的,但我已经调整过了参数了:
defaults write com.apple.versioner.python Prefer-32-Bit -bool yes

python
Python 2.7.10 (default, Jul 30 2016, 19:40:32) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import struct;print struct.calcsize("P") * 8
32

快要绝望了,求大神指点下。不吝辞谢...

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 6 条回复 时间 点赞

是比较诡异,是否可以进一步 debug,在 robotide/__init__.py 报错的位置前设置断点,看一下 library 查找路径是否有问题

# robotide/__init__.py
# 插入断点 - 调试完删除
import pdb; pdb.set_trace()
print sys.path

try:
    import wx
except ImportError as e:
    if "no appropriate 64-bit architecture" in e.message.lower() and \
       sys.platform == 'darwin':
        print("python should be executed in 32-bit mode with wxPython on OSX.")
    else:
        print(errorMessageTemplate.substitute(reason="wxPython not found."))
    sys.exit(1)

Mac 版就不要用 ride 了,那个没有想象中那么好用,可以直接在 robot 文件里面写。Mac 启动 ride 的命令不是直接调用就能起的

ovpt 回复

没看出什么问题,您看看。我是 Mac 自带的 python

>>> import wx
> /usr/local/lib/wxPython-unicode-2.8.12.1/lib/python2.7/site-packages/wx-2.8-mac-unicode/wx/__init__.py(20)<module>()
-> print sys.path
(Pdb) print sys.path
['', '/Library/Python/2.7/site-packages/requests-2.13.0-py2.7.egg', '/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg', '/Library/Python/2.7/site-packages/robot-20071211-py2.7.egg', '/Library/Python/2.7/site-packages/robotframework-3.0.2-py2.7.egg', '/Library/Python/2.7/site-packages/robotframework_ride-2.0a1-py2.7.egg', '/usr/local/lib/wxPython-unicode-2.8.12.1/lib/python2.7/site-packages', '/usr/local/lib/wxPython-unicode-2.8.12.1/lib/python2.7/site-packages/wx-2.8-mac-unicode', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Users/lazybone/Library/Python/2.7/lib/python/site-packages', '/usr/local/lib/python2.7/site-packages', '/Library/Python/2.7/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', '/usr/local/lib/wxPython-unicode-2.8.12.1/lib/python2.7']
(Pdb) import wx
徐晓东 回复

我现在是单独执行 rebot,已经 pybot 也报错了。各种诡异。
另外,我还有一台 Ubuntu 16.04 的机器,之前单独命令行下执行 pybot 1.txt 都正常的,最近执行这个命令还报 “Execution stopped by user”...

robot 
Traceback (most recent call last):
  File "/usr/local/bin/robot", line 4, in <module>
    __import__('pkg_resources').run_script('robotframework==3.0.2', 'robot')
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 742, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 1667, in run_script
    exec(code, namespace, namespace)
  File "/Library/Python/2.7/site-packages/robotframework-3.0.2-py2.7.egg/EGG-INFO/scripts/robot", line 4, in <module>
    from robot import run_cli
ImportError: cannot import name run_cli
pybot --help
Traceback (most recent call last):
  File "/usr/local/bin/pybot", line 4, in <module>
    from robot import run_cli
ImportError: cannot import name run_cli

我的思路还是 robotide/__init__.py 文件出错位置前插个断点,看下运行时的搜索路径。因为从 ride 的代码逻辑上看,import wx 时捕获到异常,就是说你单独执行 ride 命令 (相当于/usr/bin/env python ride) 的时候,找不到 “/usr/local/lib/wxPython-unicode-2.8.12.1/lib/python2.7”。我的猜测是只查找了 “/System/Library/Frameworks/Python.framework/Versions/2.7”。但是需要加上断点打印一下。

你用"python"(或者指定绝对路径的 python) 打开解释器时,sys.path 是有 wxPython 的。你可以试试指定解释器: python ride。但是上面的办法是最快最直接的。

ovpt 回复

方便单独联系下么

骨头骨头懒骨头 关闭了讨论 03月16日 18:42
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册