Put the module in the Pepper app

Overview

Procedure when you want to use a python module that is not installed as standard in Pepper

environment

procedure

Install the module using pip. Install if pip is not included

$ brew install pip

1. Download with pip

pip install [module] --no-install --no-build is no longer available Use the -d option

2. Unzip the downloaded file

Since it falls with tar, decompress it with a command

$ pip install [module] -d ./

3. Get into the project

From the Choregraphe project file Add directory for adding module with + mark Name it lib here.

4. Add the module directory to sys.path within your app

Create a box for addition.

import sys
import os

class MyClass(GeneratedClass):
    def __init__(self):
        GeneratedClass.__init__(self)
        self.path = ALFrameManager.getBehaviorPath(self.behaviorId) + "/lib"

        if self.path not in sys.path:
            sys.path.append(self.path)

    def onUnload(self):
        sys.path.remove(self.path)

    def onInput_onStart(self):
        pass

I've added a box called AddLib to the Github box library.

In python, the module in the directory append to sys.path Since it will be possible to import, the path of the lib directory added earlier is added. The AddLib box is made like a behavior under root.

Also, since the path is deleted when unloading It is recommended to place it as root.

5. Import in box

When importing, if you write it outside the class of the box Because the load process that runs at startup tries to import before sys.path.append is called Make sure to describe import in the method of class.

Github https://github.com/hws-hitorobo/custom_box

Recommended Posts

Put the module in the Pepper app
Master the weakref module in Python
Put together consecutive values in the list
Install the Python module in any directory
To add a module to python put in Julialang
Put the second axis in 2dhistgram of matplotlib
An app that you must put in Linux
Use the LibreOffice app in Python (3) Add library
Mock HTTP requests via the requests module in Responses
Try adding an external module to pepper. For the time being, in requests.
Put matplotlib in Centos7.
How to run the Ansible module added in Ansible Tower
Complement the library you put in anaconda with jedi-vim
Put jedi in emacs 24
[python] Get the list of classes defined in the module
Tab app in Tkinter
Load the module with the same name in another location
Put pip in Blender
[Note] I can't call the installed module in jupyter
Using the LibreOffice app in Python (1) Where are the macros?
Dynamically load the module.
Put the lists together in pandas to make a DataFrame
Solve the Japanese problem when using the CSV module in Python.
Download the file in Python
Find the difference in Python
About the Python module venv
Methods available in the list
Why put a slice on the left side in the substitution formula
Put logger in the open source pip package and analyze the operation
Automatically resize screenshots for the App Store for each screen in Python
[Python] Do not put Japanese in the path used by OpenCV
From the AWS cloud product page, put the AWS service name in csv