question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Python: Xray fails with "Please install a virtual environment" with venv activated

See original GitHub issue

After connecting to my Xray instance successfully and initiating a scan I get an error that claims I don’t have a virtual environment installed. Full error is:

Please install and activate a virtual environment before running Xray scan. Then, install your Python project in that environment.

My virtual environment is named ‘venv’ and lives at the root of my project. I have it selected as my virtual environment per VSCode’s instructions and have pip installed all packages to that environment. Debug log from JFrog as follows:

[INFO - 3:56:52 PM] Starting slow scan
[INFO - 3:56:52 PM] Locating go.mod files in workspace "workspace".
[DEBUG - 3:56:53 PM] No go.mod files found in workspaces.
[INFO - 3:56:53 PM] Locating package json files in workspace "workspace".
[DEBUG - 3:56:53 PM] No package.json files found in workspaces.
[INFO - 3:56:53 PM] Locating python files in workspace "workspace".
[DEBUG - 3:56:53 PM] Detected python files in workspace workspace: [file:///project/directory/requirements.txt]
[INFO - 3:56:53 PM] Locating pom.xml files in workspace "workspace".
[DEBUG - 3:56:53 PM] No pom.xml files found in workspaces.
[INFO - 3:56:53 PM] Locating *.sln files in workspace "workspace".
[DEBUG - 3:56:53 PM] No *.sln files found in workspaces.

I thought I followed the instructions in the README correctly. Any thoughts on why this might be happening?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
rderveloycommented, Apr 7, 2021

I’m having the same exact issue as @ducoterra as well. I’m running version 1.7.0 of the extension in VS Code 1.55.0 on MacOS 10.15.7. I have verified that the virtual environment is activated, that dependencies are installed, and that the virtual environment is selected in VS Code per the instructions on the extension’s detail page:

Command failed: python /Users/-----/.vscode/extensions/jfrog.jfrog-vscode-extension-1.7.0/resources/python/checkVenv.py
Error: Command failed: python /Users/-----/.vscode/extensions/jfrog.jfrog-vscode-extension-1.7.0/resources/python/checkVenv.py
	at checkExecSyncError (child_process.js:639:11)
	at Object.execSync (child_process.js:675:15)
	at Object.execSync (electron/js2c/asar_bundle.js:5:12113)
	at Function.isInVirtualEnv (/Users/-----/.vscode/extensions/jfrog.jfrog-vscode-extension-1.7.0/out/main/utils/pypiUtils.js:91:18)
	at Function.createDependenciesTrees (/Users/-----/.vscode/extensions/jfrog.jfrog-vscode-extension-1.7.0/out/main/utils/pypiUtils.js:67:28)
	at processTicksAndRejections (internal/process/task_queues.js:97:5)
	at async Function.createDependenciesTrees (/Users/-----/.vscode/extensions/jfrog.jfrog-vscode-extension-1.7.0/out/main/treeDataProviders/dependenciesTree/dependenciesTreeFactory.js:13:13)
	at async /Users/-----/.vscode/extensions/jfrog.jfrog-vscode-extension-1.7.0/out/main/treeDataProviders/dependenciesTree/dependenciesDataProvider.js:151:13
	at async /Users/-----/.vscode/extensions/jfrog.jfrog-vscode-extension-1.7.0/out/main/utils/scanUtils.js:22:13

I also get a result of 0 when running checkVenv.py with the virtual environment activated and a 1 if it’s not activated. If there are log files, can you tell me where to find them so I can include them here?

Running checkVenv.py through a debugger, it seems that virtualenv_prefix is being set to None and venv_prefix is being set to ‘/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8’, which is not the project’s activated virtual environment. The correct virtual environment is returned by sys.prefix:

(venv) laptop:test -----$ python
Python 3.8.2 (default, Aug 25 2020, 09:23:57) 
[Clang 12.0.0 (clang-1200.0.32.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.prefix)
/Users/-----/VS Code Projects/test/venv

I’m wondering if there might be a bug in isInVirtualEnv() or getPythonPath() in pypiUtils.ts since isInVirtualEnv() is obviously returning a false value given the following error message: Please install and activate a virtual environment before running Xray scan. Then, install your Python project in that environment.

0reactions
yahavicommented, Nov 3, 2021

@ducoterra @rderveloy @mlieberman85, JFrog VS-Code extension 1.8.5 is released! On this version we retrieve the Python executable path in a better way - see https://github.com/jfrog/jfrog-vscode-extension/pull/127. Feel free to upgrade - we’d appreciate your feedback on that.

@DrackThor - currently only Virtualenv is supported by the extension.

Read more comments on GitHub >

github_iconTop Results From Across the Web

venv — Creation of virtual environments — Python 3.11.1 ...
When a virtual environment has been activated, the VIRTUAL_ENV environment variable is set to the path of the environment. Since explicitly activating a...
Read more >
python - Can't "activate" virtualenv - Stack Overflow
Call the Python module venv and create a new virtual environment in the directory venv · Run the script to activate the virtual...
Read more >
Install Python, pip, and the EB CLI on Windows
To install the AWS CLI with pip (Windows) · Press the Windows key, and then enter environment variables . · Choose Edit environment...
Read more >
Installing and using virtualenv with Python 3
Virtualenv is only installed on DreamHost servers for Python 2. If you're working with Python 3, you must install virtualenv using pip3. pip3...
Read more >
pandas pypi
How to Install Python Pandas on Windows and Linux? ... to distribute their software. python - Install pandas on Mac M1 Big Sur...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found