maven build中的多个python模块导入错误

2024-06-01 20:42:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在执行maven构建中的robot测试用例。现在这些测试用例需要许多外部python模块。 当我直接执行它们(pybot)时,一切正常。在

但是当我通过maven执行它们时,对于外部python模块,它失败了。在

[ ERROR ] Error in file '/home/xyz/robot/tf2jan/Tests/CLI/mycli/mycli_resources.txt': Importing test library '/home/xyz/robot/tf2jan/lib/rest/JsonValidator.py' failed: ImportError: No module named jsonselect
Traceback (most recent call last):
  File "/home/xyz/robot/tf2jan/lib/rest/JsonValidator.py", line 6, in <module>
    from jsonselect import jsonselect
PYTHONPATH:
  /usr/lib/python2.7/dist-packages
  /home/xyz/Downloads/python-jsonpath-rw
  /home/xyz/Downloads/ply-3.10
  /home/xyz/.m2/repository/org/robotframework/robotframework/3.0.2/Lib
  /home/xyz/.m2/repository/org/robotframework/robotframework/3.0.2/robotframework-3.0.2.jar/Lib

我可以选择使用extraPathDirectories将它们添加到maven插件配置中,如下所示:

^{pr2}$

但是使用这个解决方案,我将在路径中添加太多的模块,这将使pom文件复杂化。 是否有任何其他模块自动解决这些依赖关系?在


Tags: 模块inpyresthomelibrobot测试用例
1条回答
网友
1楼 · 发布于 2024-06-01 20:42:18

由于Maven中没有Python库的依赖关系管理,我建议您:

  • 将库放在Python的默认lib目录中
  • 将库的位置添加到PYTHONPATH(因为它是由Maven检查的,请参见输出PYTHONPATH:

    编辑如果不想手动将依赖项安装到CI框中,可以尝试以下maven插件:

    <plugin>
                <groupId>com.googlecode.maven-download- plugin</groupId>
                <artifactId>download-maven-plugin</artifactId>
                <version>1.3.0</version>
                <executions>
                    <execution>
                        <id>install-a-dependency</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>wget</goal>
                        </goals>
                        <configuration>
                            <url>the_dependency_url</url>
                            <unpack>true</unpack>
                            <outputDirectory>${project.build.directory}/jbpm-3.1.4</outputDirectory>
                            <md5>df65b5642f33676313ebe4d5b69a3fff</md5>
                        </configuration>
                    </execution>
                </executions>
    </plugin>
    

https://github.com/maven-download-plugin/maven-download-plugin

相关问题 更多 >