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.
我正在尝试在使用python的程序中导入python模块请求(Choregraphe用于NAO机器人)。我不能使用sudo install等shell命令......我只能通过将模块移动到项目的lib文件夹中来导入模块。
So I've downloaded requests from pypi, and I've also downoaded requirements that I've moved into requests folder (https://i.imgur.com/XXlSz0N.png). But when I try to import requests from the program, it returns me an error:
所以我已经从pypi下载了请求,并且我也已经下载了我已经移入请求文件夹(https://i.imgur.com/XXlSz0N.png)的要求。但是当我尝试从程序导入请求时,它返回一个错误:
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?
为什么我看到这个错误?
2 个解决方案
#1
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?
在Choregraphe包中包含依赖库可能很棘手(您需要确保它们是针对正确的体系结构进行编译的,并且对于虚拟机器人而言,事情会有所不同) - 但首先,您是否确保这些库尚未在机器人?
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)
我知道Pepper上包含“请求”;它可能包括在Nao(我认为它是但我没有一个方便的Nao检查);如果它是你不需要担心将它包含在你的包中(你可能必须在虚拟机器人上运行时修改pythonpath ...但在所有情况下你应该能够依赖系统请求而不打包它)
#2
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:
如果您使用Choregraphe,您可以执行此操作:将lib文件夹放在Choregraphe项目文件夹中。在Choregraphe中创建一个python脚本并将其粘贴到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
#1
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?
在Choregraphe包中包含依赖库可能很棘手(您需要确保它们是针对正确的体系结构进行编译的,并且对于虚拟机器人而言,事情会有所不同) - 但首先,您是否确保这些库尚未在机器人?
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)
我知道Pepper上包含“请求”;它可能包括在Nao(我认为它是但我没有一个方便的Nao检查);如果它是你不需要担心将它包含在你的包中(你可能必须在虚拟机器人上运行时修改pythonpath ...但在所有情况下你应该能够依赖系统请求而不打包它)
#2
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:
如果您使用Choregraphe,您可以执行此操作:将lib文件夹放在Choregraphe项目文件夹中。在Choregraphe中创建一个python脚本并将其粘贴到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