title: How to install packages with python scripts
body: <p>I want to install a package with a python script. I have read the documentation about PackageManager API (<a href="http://doc.aldebaran.com/2-4/naoqi/core/packagemanager-api.html" rel="nofollow noreferrer">http://doc.aldebaran.com/2-4/naoqi/core/packagemanager-api.html</a>):</p>
  
  <p>So I have packaged the app with choregraphe as it is described in <a href="http://doc.aldebaran.com/2-4/naoqi/core/packagemanager.html" rel="nofollow noreferrer">http://doc.aldebaran.com/2-4/naoqi/core/packagemanager.html</a> and I have tried to install it with a python script that looks like:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>And here is what I receive as an error:</p>
  
  <pre><code># provided package could be opened
  &lt;open file 'C:\\test_package_handlers_01-835a92-1.0.0.pkg', mode 'r' at 0x02886288&gt;
  Traceback (most recent call last):
    File "C:/test.py", line 24, in &lt;module&gt;
      service.install(package)
  RuntimeError: C:\test_package_handlers_01-835a92-1.0.0.pkg: no such file
  </code></pre>
  
  <p>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. </p>
  
  <p><b>EDITED</b></p>
  
  <p>I have added the package to a choreographe blank project and run this blank project on the robot. This way the package was saved to the robot with path <code>/home/nao/.local/share/PackageManager/apps/.lastUploadedChoregrapheBehavior/test_package_handlers_01-835a92-1.0.0.pkg</code> and when I have changed the path in my script (<code>"C:\\test_package_handlers_01-835a92-1.0.0.pkg"</code> with <code>"/home/nao/.local/share/PackageManager/apps/.lastUploadedChoregrapheBehavior/test_package_handlers_01-835a92-1.0.0.pkg"</code>) the script worked as it was intended and the package was installed on the robot.</p>
  
  <p>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. </p>
  
  <p>Maybe it is good to give the following explanation of what I want to achieve:</p>
  
  <ul>
  <li>I have a folder on my PC with 20 packages for example</li>
  <li>I want to install all those 20 packages with one python script</li>
  <li>There is a python script that installs all the packages from the folder when it is invoked like this:
  <code>python package_installer.py path_to_packages_folder</code></li>
  </ul>
  
  <p><b>EDITED_2</b></p>
  
  <pre><code>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()
  </code></pre>
  
  <p>This piece of code <code>ftp = ftplib.FTP(ROBOT_URL)</code> throws the following exception:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:/Stefan/DSK_PEPPER_clode_2/PythonScripts/_local_testing/uploading_and_installing_package.py", line 11, in &lt;module&gt;
      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
  </code></pre>
  
  <p>Also when I connect to the robot with username 'nao' and pass 'nao' as described in <a href="http://doc.aldebaran.com/2-5/dev/tools/opennao.html" rel="nofollow noreferrer">http://doc.aldebaran.com/2-5/dev/tools/opennao.html</a> and then try to create a folder in <code>/home/nao/.local/share/PackageManager/apps/</code> with <code>sudo mkdir</code> it informs me that: <code>Sorry, user nao is not allowed to execute '/bin/mkdir dasdas' as root on Pepper.</code>. If I use only <code>mkdir</code> here is what it tells me: <code>mkdir: cannot create directory 'new_folder': Permission denied</code></p>