Snyk test returns Failed to test pip project error

6.6k Views Asked by At

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
4

There are 4 best solutions below

0
On

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
1
On

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! :)

1
On

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
1
On

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.