1

I'm trying to import python module requests in a program that uses python (Choregraphe for NAO the robot). I can't use shell commands like sudo install etc... I can only import module by moving the module into lib folder of the project.

So I've downloaded requests from pypi, and I've also downoaded requirements that I've moved into requests folder (https://i.stack.imgur.com/JpTqD.png). But when I try to import requests from the program, it returns me an error:

File "C:\Users\gurfe\AppData\Roaming\PackageManager\apps\.lastUploadedChoregrapheBehavior\behavior_1\../lib\requests\__init__.py", line 112, in <module>
    from . import utils
ImportError: cannot import name utils

Why do I see this error?

jpp
  • 159,742
  • 34
  • 281
  • 339
  • The dependencies shouldn't be _in_ the `requests` folder. The dependencies are python modules just like `requests`, so they should be in the same folder as `requests`. – Aran-Fey Mar 23 '18 at 17:53
  • 1
    Why are you downloading packages and moving them around into other packages? Just `pip install requests`. – abarnert Mar 23 '18 at 17:54
  • 1
    _"I can't use shell commands like sudo install"_ That doesn't surprise me, given that you're on Windows. Can you use `pip install --user requests`? – Aran-Fey Mar 23 '18 at 17:58
  • I can't use any of commands, because this project will be uploaded and loaded into the robot. So, is there any method to solve problem without writing commands like 'pip intall --user requests' or 'pip intall requests'? – Federico Giuriato Mar 24 '18 at 18:16
  • @Aran-Fey but those modules are in their folders (like urllib3 folder, with inside all its scripts and __init__.py) which are inside the requests folder – Federico Giuriato Mar 24 '18 at 18:28

2 Answers2

0

Including dependency libraries in your Choregraphe package can be tricky (you need to make sure they are compiled for the right architecture, and things will work differently for a virtual robot) - but first, did you make sure that these libraries are not already on the robot?

I know "requests" is included on Pepper; it may be included on Nao (I think it is but I don't have a handy Nao to check); if it is you don't need to worry about including it in your package (you may have to modify the pythonpath when running on a virtual robot... but in all cases you should be able to rely on a system requests without packaging it)

Emile
  • 2,946
  • 2
  • 19
  • 22
0

If you use Choregraphe you can do this: Place the lib folder in your Choregraphe project folder. Create a python script in Choregraphe and paste this in init:

class MyClass(GeneratedClass):
    def __init__(self):
        GeneratedClass.__init__(self)
        self.logger.warning("import only works on physical robot")
        behaviorPath = ALFrameManager.getBehaviorPath(self.behaviorId)
        sys.path.append(behaviorPath)
        k = behaviorPath.rfind("/")
        packagePath = behaviorPath[:k]
        sys.path.append(packagePath)

        import utils
        self.utils = utils
Anders_K
  • 982
  • 9
  • 28