Problems using PyPy conda virtual environments within VSCode (on Windows)

75 Views Asked by At

I'm trying to evaluate different Python environments within VSCode, specifically CPython 3.11, CPython 3.9.16 and PyPy (7.3.11). The aim is to create desired environments in conda, and use these against a target code base within VSCode. I'm running VSCode on Windows 10:

  • Extension version: 2022.8.0
  • VS Code version: Code 1.79.2 (695af097c7bd098fbf017ce3ac85e09bbc5dda06, 2023-06-14T08:57:04.379Z)

First, one can create a simple piece of test code which is anticipated to highlight the benefits of PyPy vs CPython:

from time import perf_counter  
from platform import python_version

print(python_version())

total = 0  
st = perf_counter()  
for i in range(int(1E3)):  
    for j in range(int(1E3)):  
        total += (i + j)

fin = perf_counter()

Creating conda environments for CPython:

conda create --name <my-env-name> python=<my-py-version>

and subsequently selecting an interpreter for those environments in VSCode enables one to "Run Python..." and/or "Debug Python.." and hit set breakpoints in the test code and retrieve output in the terminal with each respective CPython environment.

(base) D:\>C:/tools/miniconda3/python.exe d:/demo.py  
3\.9.16  
Task took: 0.23066479999999998secs
(base) D:\>C:/tools/miniconda3/envs/py-311/python.exe d:/demo.py  
3\.11.3  
Task took: 0.19787699996959418secs

One can then create a PyPy environment following the advice from PyPy:

conda create -c conda-forge -n my-pypy-env pypy python=3.8

This creates a PyPy environment successfully.

Selecting the PyPy interpreter environment in VSCode immediately yields an error:

The isort server crashed 5 times in the last 3 minutes. The server will not be restarted

The iSort output yields:

\[Info - 4:50:39 PM\] Connection to server got closed. Server will restart.  
\[Info - 4:50:39 PM\] Connection to server got closed. Server will restart.  
\[Info - 4:50:39 PM\] Connection to server got closed. Server will restart.  
\[Info - 4:50:39 PM\] Connection to server got closed. Server will restart.  
\[Error - 4:50:40 PM\] Connection to server got closed. Server will not be restarted.

Subsequently trying to "Debug Python..." with the PyPy environment selected completely fails... literally nothing happens and seemingly nothing can be done to change this

If one tries to "Run Python..." when a PyPy environment (pypy-env) is selected as the interpreter, but CPython environment is active in the terminal, nothing happens:

(py-311) D:\>C:/tools/miniconda3/envs/pypy-env/python.exe d:/demo.py

(py-311) D:\>

If one subsequently forces activation of the pypy-env in the terminal, and invoke "Run Python...", the code in the PyPy environment executes:

(base) D:\>conda activate pypy-env

(pypy-env) D:\>C:/tools/miniconda3/envs/pypy-env/python.exe d:/demo.py  
3\.8.16  
Task took: 0.0072821secs

(pypy-env) D:\>

However, one can happily run CPython interpreters when a PyPy environment is activated in the terminal:

(pypy-env) D:\>C:/tools/miniconda3/envs/py-311/python.exe d:/demo.py  
3\.11.3  
Task took: 0.19779740006197244secs

(pypy-env) D:\>

The test code runs correctly when invoked from the command line with either CPython or PyPy virtual environment active, so it doesn't appear to be a issue with the virtual environments.

It seems apparent that VSCode and iSort server are operating correctly when CPython environments are used. Selecting PyPy environments clearly compromises the iSort server which then in turn appears to compromise VSCode "Run Python File..." and "Debug Python File..." behaviour.

On the strong assumption that this is a genuine bug in VSCode's iSort server, I have raised an issue with the iSort team. However, I am mindful what I am seeing could be due to "something else". Accordingly I'd love to know:

  • Has anyone got PyPy running under VSCode? (with all "Run..." & "Debug.." functionality working correctly)
  • If so, how did you achieve this? (using virtual environments)
0

There are 0 best solutions below