8

I'm running security scan with Snyk CLI for python project. Unfortunately snyk test command returns Failed to test pip project error. What am I missing, snyk test works just fine while scanning npm project ?

$ snyk test --file=requirements.txt
Failed to test pip project
Lukasz Dynowski
  • 11,169
  • 9
  • 81
  • 124

4 Answers4

5

I found the cause basically you need to do two things:

  • Make sure that packages that your project uses are installed.
  • Make sure that you are using correct python.

Solution

$ pip3 install -r requirements.txt
$ snyk test --file=requirements.txt --command=python3

Info

You can bypass missing python packages by passing the --allow-missing pip parameter through snyk by using the additional -- argument.

$ snyk test --file=requirements.txt --command=python3 -- --allow-missing

Docs

-- [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
Lukasz Dynowski
  • 11,169
  • 9
  • 81
  • 124
  • Thanks, I also had to add `--file=requirements.txt --command=python3` to the VSCode additional parameters field, under the snyk extension settings wheel. – pbnelson Sep 20 '22 at 18:05
0

snyk monitor command will also return undefined if it is not ran with

pip3 install -r requirements.txt
snyk test --file=requirements.txt --command=python3
snyk monitor --file=requirements.txt --command=python3
Amal
  • 9
  • 5
0

If you are using virtual environments, then make sure you have activated the venv with

. venv/Scripts/activate

Then try running Snyk Test again.

Snyk monitor and other cli commands should work from that! :)

TecHunter
  • 6,091
  • 2
  • 30
  • 47
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 28 '22 at 08:35
0

If you are using Snyk and VScode, and you open a repo that has a Python VirtualEnv, you can get this error in your VScode terminal window.

  • [Error] Open Source Security test failed for "/home/{user}/path/to/repo". Failed to test pip project

Fix for VScode:

  1. Close that VScode window.
  2. From a terminal, navigate to the top folder of that repo.
  3. Run the command to activate the virtual env
    • Example: . .venv/bin/activate
  4. Open VScode for that folder
    • Example: run code .

The Snyk Open Source Security test should run without that error now.

Robert Echlin
  • 623
  • 5
  • 6