[英]How to install packages with python scripts
I want to install a package with a python script. 我想使用python脚本安装软件包。 I have read the documentation about PackageManager API ( http://doc.aldebaran.com/2-4/naoqi/core/packagemanager-api.html ): 我已经阅读了关于PackageManager API的文档( http://doc.aldebaran.com/2-4/naoqi/core/packagemanager-api.html ):
So I have packaged the app with choregraphe as it is described in http://doc.aldebaran.com/2-4/naoqi/core/packagemanager.html and I have tried to install it with a python script that looks like: 因此,我将应用程序与choregraphe打包在一起,如http://doc.aldebaran.com/2-4/naoqi/core/packagemanager.html中所述,并且我尝试使用如下所示的python脚本进行安装:
import qi
import sys
if __name__ == '__main__':
ip = "11.1.11.111"
port = 9559
session = qi.Session()
try:
session.connect("tcp://" + ip + ":" + str(port))
except RuntimeError:
print ("Can't connect to Naoqi at ip \"" + ip + "\" on port " + str(port))
sys.exit(1)
service = session.service("PackageManager")
package = "C:\\test_package_handlers_01-835a92-1.0.0.pkg"
# this is to see if the problem is that python can not locate the file
with open(package) as f:
print f
service.install(package)
And here is what I receive as an error: 这是我收到的错误消息:
# provided package could be opened
<open file 'C:\\test_package_handlers_01-835a92-1.0.0.pkg', mode 'r' at 0x02886288>
Traceback (most recent call last):
File "C:/test.py", line 24, in <module>
service.install(package)
RuntimeError: C:\test_package_handlers_01-835a92-1.0.0.pkg: no such file
I guess this is because the package must be uploaded on the robot and the package file path must be the one that is on the robot. 我猜这是因为必须将软件包上载到机器人上,并且软件包文件路径必须是机器人上的文件路径。
EDITED 已编辑
I have added the package to a choreographe blank project and run this blank project on the robot. 我已将软件包添加到Choreographe空白项目中,并在机器人上运行了该空白项目。 This way the package was saved to the robot with path /home/nao/.local/share/PackageManager/apps/.lastUploadedChoregrapheBehavior/test_package_handlers_01-835a92-1.0.0.pkg
and when I have changed the path in my script ( "C:\\\\test_package_handlers_01-835a92-1.0.0.pkg"
with "/home/nao/.local/share/PackageManager/apps/.lastUploadedChoregrapheBehavior/test_package_handlers_01-835a92-1.0.0.pkg"
) the script worked as it was intended and the package was installed on the robot. 这样,包被保存到与路径机器人/home/nao/.local/share/PackageManager/apps/.lastUploadedChoregrapheBehavior/test_package_handlers_01-835a92-1.0.0.pkg
,当我在我的脚本已经改变了路径( "C:\\\\test_package_handlers_01-835a92-1.0.0.pkg"
和"/home/nao/.local/share/PackageManager/apps/.lastUploadedChoregrapheBehavior/test_package_handlers_01-835a92-1.0.0.pkg"
),脚本按预期工作并将软件包安装在机器人上。
So is there a way to install packages from my PC without uploading them to the robot, because otherwise it is better to use Choregraphe to upload projects. 因此,有一种方法可以从我的PC安装软件包而不将其上传到机械手,因为否则最好使用Choregraphe上载项目。
Maybe it is good to give the following explanation of what I want to achieve: 对我要实现的目标给出以下解释也许是一件好事:
python package_installer.py path_to_packages_folder
像这样调用时,有一个Python脚本会安装文件夹中的所有软件包: python package_installer.py path_to_packages_folder
EDITED_2 EDITED_2
import qi
import ftplib
import os
ROBOT_URL = "10.80.129.90"
print "Uploading PKG"
pkg_file = "my-application-0.0.1.pkg"
pkg_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), pkg_file)
ftp = ftplib.FTP(ROBOT_URL)
ftp.login("nao", "nao")
with open(pkg_path) as pkg:
ftp.storbinary("STOR "+pkg_file, pkg)
print "Connecting NAOqi session"
app = qi.Application(url='tcp://'+ROBOT_URL+':9559')
app.start()
session = app.session
print "Installing app"
packagemgr = session.service("PackageManager")
packagemgr.install("/home/nao/"+pkg_file)
print "Cleaning robot"
ftp.delete(pkg_file)
ftp.quit()
print "End"
app.stop()
This piece of code ftp = ftplib.FTP(ROBOT_URL)
throws the following exception: 这段代码ftp = ftplib.FTP(ROBOT_URL)
引发以下异常:
Traceback (most recent call last):
File "C:/Stefan/DSK_PEPPER_clode_2/PythonScripts/_local_testing/uploading_and_installing_package.py", line 11, in <module>
ftp = ftplib.FTP(ROBOT_URL)
File "C:\Python27\lib\ftplib.py", line 120, in __init__
self.connect(host)
File "C:\Python27\lib\ftplib.py", line 135, in connect
self.sock = socket.create_connection((self.host, self.port), self.timeout)
File "C:\Python27\lib\socket.py", line 575, in create_connection
raise err
socket.error: [Errno 10061] No connection could be made because the target machine actively refused it
Also when I connect to the robot with username 'nao' and pass 'nao' as described in http://doc.aldebaran.com/2-5/dev/tools/opennao.html and then try to create a folder in /home/nao/.local/share/PackageManager/apps/
with sudo mkdir
it informs me that: Sorry, user nao is not allowed to execute '/bin/mkdir dasdas' as root on Pepper.
同样,当我使用用户名“ nao”连接到机器人并按照http://doc.aldebaran.com/2-5/dev/tools/opennao.html中的说明传递“ nao”,然后尝试在/home/nao/.local/share/PackageManager/apps/
创建文件夹/home/nao/.local/share/PackageManager/apps/
带有sudo mkdir
它通知我: Sorry, user nao is not allowed to execute '/bin/mkdir dasdas' as root on Pepper.
. 。 If I use only mkdir
here is what it tells me: mkdir: cannot create directory 'new_folder': Permission denied
如果我仅使用mkdir
,这将告诉我: mkdir: cannot create directory 'new_folder': Permission denied
使用qibuild ,您还可以使用以下命令直接安装:
qipkg deploy-package /path/to/my-package.pkg --url nao@10.10.23.45
You indeed need to upload the file before. 您确实确实需要先上传文件。 You can use scp
or sftp
to do this. 您可以使用scp
或sftp
来执行此操作。 Once the .pkg
is on the robot then you can use PackageManager.install
. 将.pkg
放置在机械PackageManager.install
后,即可使用PackageManager.install
。
Imagine something like: 想象一下:
import qi
import paramiko
import os
ROBOT_URL = "10.80.129.90"
print "Uploading PKG"
pkg_file = "my-application-0.0.1.pkg"
pkg_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), pkg_file)
transport = paramiko.Transport((ROBOT_URL, 22))
transport.connect(username="nao", password="nao")
sftp = paramiko.SFTPClient.from_transport(transport)
sftp.put(pkg_path, pkg_file)
print "Connecting NAOqi session"
app = qi.Application(url='tcp://'+ROBOT_URL+':9559')
app.start()
session = app.session
print "Installing app"
packagemgr = session.service("PackageManager")
packagemgr.install("/home/nao/"+pkg_file)
print "Cleaning robot"
sftp.remove(pkg_file)
sftp.close()
transport.close()
print "End"
app.stop()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.