Skip to content

Selected pipenv virtualenv is written to python.pythonPath #15634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Urkallinger opened this issue Mar 11, 2021 · 12 comments
Closed

Selected pipenv virtualenv is written to python.pythonPath #15634

Urkallinger opened this issue Mar 11, 2021 · 12 comments
Assignees
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster

Comments

@Urkallinger
Copy link

Urkallinger commented Mar 11, 2021

Since some time (I can't say when exactly) the virutalenv is not recognized in my project. I open the project folder with vs code and as soon as the python extension is loaded, the system wide installation of python is recognized as interpreter, although there is a pipfile in my project folder.

Environment data

  • VS Code version: 1.54.1
  • Extension version (available under the Extensions sidebar): v2021.2.636928669
  • OS and version: Windows 10, 20H2
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.3
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): pipenv virutalenv
  • Value of the python.languageServer setting: Pylance

Expected behaviour

the virutalenv is recognized and I don't have to set the "python.pythonPath" setting explicitly.

Actual behaviour

The system-wide Python installation is selected as interpreter.
When I change the interpreter to the pipenv virtualenv, the absolute path is entered into my settings.json.
This is problematic because the virutalenv is in my user directory and so the path is not correct for all developers involved.

Details

The corresponding virtualenv is marked as "(cached)" in the interpreter selection.

I already tried the following commands:

  • Python: Clear Workspace Interpreter Settings
  • Python: Reset Stored Info for Untrusted Interpreters

both had no effect.

i also reinstalled vs code and deleted the folders in %appdata%, but still the virutalenv was not detected.

@Urkallinger Urkallinger added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Mar 11, 2021
@karthiknadig karthiknadig added area-environments Features relating to handling interpreter environments triage labels Mar 11, 2021
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Mar 11, 2021
@kimadeline
Copy link

Hi @Urkallinger, thank you for reaching out!

We made some changes to interpreter discovery (#12020), could you give them a try?

To do so, open your machine's setting.json (use the command "Preferences: Open Settings (JSON") and add the following:

"python.experiments.optInto": [        
        "pythonDiscoveryModule"
    ],

@Urkallinger
Copy link
Author

Urkallinger commented Mar 12, 2021

Hi @kimadeline,
thanks for the quick response!

I have copied the setting into my settings. I also deleted the entry "python.pythonPath" from the workspace settings. After that I restarted vs code. Unfortunately the system wide Python was selected as interpreter again.
I executed the two commands "Python: Clear Workspace Interpreter Settings" and "Python: Reset Stored Info for Untrusted Interpreters" and restarted. Unfortunately also without success.

I have installed pipenv (version 2020.11.15) in my system-wide Python. When I call the following command with it, it gives me the correct path to virtualenv in my user directory:
pipenv --venv

@kimadeline
Copy link

Sorry for the response delay, and thank you for your patience!

A couple of things here:

  • The 2 commands that you ran ("Python: Clear Workspace Interpreter Settings" and "Python: Reset Stored Info for Untrusted Interpreters") have an effect only if you are in the DeprecatePythonPath experiment.
  • We don't perform pipenv discovery on extension activation anymore (Remove pipenv discovery from interpreter discovery on activation #11127), so your environment will not be auto detected until you select it at least once. Does your environment appear in the list of interpreters when you click on the interpreter in the status bar (bottom left)?

@kimadeline kimadeline added the info-needed Issue requires more information from poster label Mar 24, 2021
@Urkallinger
Copy link
Author

My environment is correctly detected and offered in the dropdown:

detected_environments

As soon as I select my environment then, I get the entry

"python.pythonPath": "C:\\Users\\user\\.virtualenvs\\envname\\Scripts\\python.exe",

in my workspace settings.

If I delete this entry, the system-wide python installation (C:\Python37\python.exe) is selected again. This remains so after a reboot.

@kimadeline
Copy link

Could you copy here the output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)?

Also, just to confirm, how did you create your virtual environment? Does the issue happen with newly created environments as well?

@Urkallinger
Copy link
Author

Output panel

User belongs to experiment group 'pythonDiscoveryModule'
User belongs to experiment group 'pythonaacf'
User belongs to experiment group 'pythonSendEntireLineToREPL'
User belongs to experiment group 'pythonNotDisplayLinterPrompt'
User belongs to experiment group 'pythonDiscoveryModulecf'
User belongs to experiment group 'pythonTensorboardExperiment'
User belongs to experiment group 'PythonPyTorchProfiler'
User belongs to experiment group 'ShowExtensionSurveyPrompt - control'
User belongs to experiment group 'CollectLSRequestTiming - control'
> python c:\Users\username\.vscode\extensions\ms-python.python-2021.3.680753044\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python c:\Users\username\.vscode\extensions\ms-python.python-2021.3.680753044\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
Python interpreter path: C:\Python37\python.exe
Starting Pylance language server.
> conda --version

how did you create your virtual environment?

The virtualenv is created and also updated as follows (these steps are automated by a python script):

  • creation of the virtualenv by pipenv (C:\Python37\python.exe -m pipenv run python)
  • install pip 20.2.4 (C:\Python37\Scripts\pipenv.exe run python -m pip install pip==20.2.4)
  • clean (C:\Python37\Scripts\pipenv.exe run pipenv clean)
  • sync (C:\Python37\Scripts\pipenv.exe run pipenv sync --dev --pypi-mirror <mirror1> --pypi-mirror <mirror2> --pypi-mirror <mirror3>)

Does the issue happen with newly created environments as well?

Yes, even then this behavior occurs.
I proceeded as follows:

  • mkdir vscode_pipenv_test
  • cd vscode_pipenv_test
  • pipenv --python 3.7
  • code .

The system-wide python is now selected as interpreter. If I select the just created virutalenv, the path is entered in the settings. If I delete the entry, the system-wide python is selected again.

The problem occurs on the notebook I have from my company. Can it be a permission problem?

@kimadeline kimadeline changed the title pipenv virtualenv is not recognized Selected pipenv virtualenv is written to python.pythonPath Apr 20, 2021
@kimadeline
Copy link

I may have misunderstood your issue 🙈 Can you try setting the following in your global settings.json:

"python.experiments.optInto": [        
        "pythonDiscoveryModule"
]

and then reload VS Code and select your interpreter?

@Urkallinger
Copy link
Author

Sorry, my title was indeed misleading.

You had recommended the experiment "pythonDiscoveryModule" to me some time ago.

Hi @Urkallinger, thank you for reaching out!

We made some changes to interpreter discovery (#12020), could you give them a try?

To do so, open your machine's setting.json (use the command "Preferences: Open Settings (JSON") and add the following:

"python.experiments.optInto": [        
        "pythonDiscoveryModule"
    ],

I tried it back then, unfortunately without success.

I tried it again today with the current version of the Python Extension (v2021.4.765268190). But it still does not work. As before, in my workspace settings python.pythonPath is set. ☹

@kimadeline
Copy link

Ahhhh my apologies I made a typo! I meant to reuse the json snippet but didn't replace the experiment, it was supposed to be:

"python.experiments.optInto": [        
        "DeprecatePythonPath - experiment"
]

@Urkallinger
Copy link
Author

With the "DeprecatePythonPath - experiment" experiment, everything works exactly as expected.
I select my virtual environment, no entry is created in my settings and the selected virtual environment remains even after a restart of vs code.

@kimadeline
Copy link

Thank you for reporting back, glad to hear it works now!

@sidneydemoraes
Copy link

Ahhhh my apologies I made a typo! I meant to reuse the json snippet but didn't replace the experiment, it was supposed to be:

"python.experiments.optInto": [        
        "DeprecatePythonPath - experiment"
]

I had the same issue and confirm this solution works.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

4 participants