我正在使用Snyk CLI为python项目运行安全扫描。不幸的是,snyk test
命令返回测试pip项目失败错误。我缺少什么,snyk test
在扫描npm
项目时工作得很好?
$ snyk test --file=requirements.txt
Failed to test pip project
我发现原因基本上需要做两件事:
- 确保项目使用的包已安装
- 确保您使用的是正确的python
解决方案
$ pip3 install -r requirements.txt
$ snyk test --file=requirements.txt --command=python3
信息
您可以通过使用额外的--
参数通过snyk传递--allow-missing
pip参数来绕过丢失的python包。
$ snyk test --file=requirements.txt --command=python3 -- --allow-missing
文档
-- [COMPILER_OPTIONS]
Pass extra arguments directly to Gradle or Maven. E.g. snyk test
-- --build-cache
Python options
--command=COMMAND
Indicate which specific Python commands to use based on Python
version. The default is python which executes your systems de-
fault python version. Run 'python -V' to find out what version
is it. If you are using multiple Python versions, use this pa-
rameter to specify the correct Python command for execution.
Default: python Example: --command=python3
snyk monitor命令如果不使用运行,也将返回未定义
pip3 install -r requirements.txt
snyk test --file=requirements.txt --command=python3
snyk monitor --file=requirements.txt --command=python3
如果您正在使用Snyk和VScode,并且您打开了一个具有Python VirtualEnv的repo,则可以在VScode终端窗口中获得此错误。
- [Error]"的开源安全测试失败/home/{user}/path/to/repo";。测试pip项目失败
修复VScode:
- 关闭VScode窗口
- 从终端导航到该repo的顶部文件夹
- 运行命令以激活虚拟环境
- 示例:
. .venv/bin/activate
- 示例:
- 打开该文件夹的VScode
- 示例:运行
code .
- 示例:运行
Snyk开源安全测试现在应该可以在没有该错误的情况下运行。
如果您使用的是虚拟环境,请确保您已使用激活venv
. venv/Scripts/activate
然后再次尝试运行Snyk测试。
Snyk monitor和其他cli命令应该从此开始工作!:(