Robot Framework应用——在Virtualenv和Virtualwrapper的虚拟环境中启动Robot Framework的RIDE时报的错误问题的解决

Posted 我是干勾鱼

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Robot Framework应用——在Virtualenv和Virtualwrapper的虚拟环境中启动Robot Framework的RIDE时报的错误问题的解决相关的知识,希望对你有一定的参考价值。

转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/116706660
本文出自【我是干勾鱼的博客

之前在Robot Framework应用——Mac环境下Robot Framework的安装及简单实用中讲解了Mac环境下Robot Framework的安装。经常会在虚拟环境下使用Python,之前在使用Virtualenv和Virtualwrapper创建Python虚拟环境中曾经讲解过Python虚拟环境的搭建,而在安装Robot Framework的时候,如果Python是在虚拟环境中,会遇到一些问题。

第一个错误:

$ ./script.sh ride.py
This program needs access to the screen. Please run with a
Framework build of python, and only when you are logged in
on the main display of your Mac.

报错This program needs access to the screen. Please run with a Framework build of python…这篇文章中提到了这个问题,思路是通过wxPythonVirtualenvOnMac这篇文章解决的,笔者这里使用的是Python3.6,如果设置成Python3.6的环境:

#!/bin/bash
  
# what real Python executable to use
PYVER=3.6
PYTHON=/Library/Frameworks/Python.framework/Versions/$PYVER/bin/python$PYVER

# find the root of the virtualenv, it should be the parent of the dir this script is in
ENV=`$PYTHON -c "import os; print os.path.abspath(os.path.join(os.path.dirname(\\"$0\\"), '..'))"`

# now run Python with the virtualenv set as Python's HOME
export PYTHONHOME=$ENV
exec $PYTHON "$@"

,所以在script.sh这个配置文件中设置Python3.6的环境应该是不太合适的,还是应该设置Python2.7的环境,还会报错:

$ ./script.sh ride.py
  File "<string>", line 1
    import os; print os.path.abspath(os.path.join(os.path.dirname("./script.sh"), '..'))
                      ^
SyntaxError: invalid syntax
Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00007fffaabc3380 (most recent call first):
Abort trap: 6

并且Python退出了:

在虚拟环境下执行Python,发现是Python2.7的环境:

$ python
Python 2.7.10 (default, Oct  6 2017, 22:29:07) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

所以在script.sh这个配置文件中设置Python3.6的环境应该是不太合适的,还是应该设置Python2.7的环境。另外这里要注意,Python2.7与Python2.6的安装目录私有区别的:

  • Python2.7:/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python$PYVER

  • Python3.6:/Library/Frameworks/Python.framework/Versions/ P Y V E R / b i n / p y t h o n PYVER/bin/python PYVER/bin/pythonPYVER

Python2.7是“/System/Library/。。。”目录下,而Python3.6直接是在“/Library/。。。”目录下。

#!/bin/bash
  
# what real Python executable to use
PYVER=2.7
PYTHON=/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python$PYVER

# find the root of the virtualenv, it should be the parent of the dir this script is in
ENV=`$PYTHON -c "import os; print os.path.abspath(os.path.join(os.path.dirname(\\"$0\\"), '..'))"`

# now run Python with the virtualenv set as Python's HOME
export PYTHONHOME=$ENV
exec $PYTHON "$@"

参考:

Robot Framework应用——Mac环境下Robot Framework的安装及简单实用

使用Virtualenv和Virtualwrapper创建Python虚拟环境

报错This program needs access to the screen. Please run with a Framework build of python…

wxPythonVirtualenvOnMac

Mac下安装配置Python2和Python3并相互切换使用

以上是关于Robot Framework应用——在Virtualenv和Virtualwrapper的虚拟环境中启动Robot Framework的RIDE时报的错误问题的解决的主要内容,如果未能解决你的问题,请参考以下文章

Robot Framework应用——Mac环境下Robot Framework的安装及简单实用

Robot Framework应用——Mac环境下Robot Framework的安装及简单实用

ROBOT Framework无法单击弹出接受按钮

如何使用 Appium 滚动 Robot Framework 以在 Android 设备上测试应用程序

Robot Framework——自动化示例

如何将数据驱动的概念应用于 Robot Framework 中的用户关键字?