Skip to content
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

The Python version is display wrong when use the latest python to create Conda environment. #6749

Closed
linette-zyy opened this issue Oct 8, 2021 · 12 comments · Fixed by #6902
Assignees

Comments

@linette-zyy
Copy link

Environment
image

Steps to Reproduce

  1. Create a Python project
  2. Right click Python Environments -> Add Environment -> Conda environment
  3. Choose the latest python version to create
    image
  4. Click Create button
  5. Observes

Expected behavior
The environment is created successfully and display without aby error.

Additional context and screenshots
The Python version is display wrong when use the latest python to create Conda environment.
It displayed Python0.0, it should display Python 3.10
image

@AdamYoblick
Copy link
Member

I'm able to repro this. When I try to get the python version from the minicondo environment, I get an error:

C:\Users\advolker\Miniconda3\envs\env\python.exe -V

image

Maybe this has something to do with it. Need to dig into the environments window to see how we're getting the version number from the environment.

@int19h
Copy link
Contributor

int19h commented Oct 9, 2021

The way it retrieves the version for non-root Conda environments is by printing out sys.version_info and then parsing that back on VS side:

var version = CPythonInterpreterFactoryProvider.VersionFromSysVersionInfo(interpreterPath);

public static Version VersionFromSysVersionInfo(string interpreterPath) {
Version version = null;
using (var output = ProcessOutput.RunHiddenAndCapture(
interpreterPath, "-c", "import sys; print('%s.%s' % (sys.version_info[0], sys.version_info[1]))"
)) {
output.Wait();
if (output.ExitCode == 0) {
var versionName = output.StandardOutputLines.FirstOrDefault() ?? "";
if (!Version.TryParse(versionName, out version)) {
version = null;
}
}
}
return version;
}

So yes, this error would also break that.

These types of errors from Conda usually indicate that it has been executed without activating it properly.

Now, previously, I have only seen this when importing some module that had a native dependency - so you could still run python.exe directly without activation. So the original logic for version detection did work.

It appears that, with Python 3.10, this is no longer the case, and the zlib dependency is directly from the DLL. So for 3.10+, python.exe in non-activated Conda environments is unusable. We'll either need to run the version-retrieval script in an activated environment, or figure out some other way of determining the version.

@linette-zyy
Copy link
Author

This issue also occurred on Dev16
image

@ttSpace
Copy link

ttSpace commented Oct 13, 2021

In today's build I can not use the latest pyton to create Conda environment to my Project.

something

@linette-zyy
Copy link
Author

@AdamYoblick
This issue also can reproduce on the latest build.
image
I try to create Conda environment and modify the python version.
Choose Python 3.10 and Python(latest)
image
After create successfully, it still display "python 0.0"
image

@AdamYoblick
Copy link
Member

I was able to repro this as well when selecting both python (latest) and python 3.10. I will investigate.

@AdamYoblick AdamYoblick self-assigned this Mar 3, 2022
@AdamYoblick
Copy link
Member

AdamYoblick commented Mar 3, 2022

The way it retrieves the version for non-root Conda environments is by printing out sys.version_info and then parsing that back on VS side:

var version = CPythonInterpreterFactoryProvider.VersionFromSysVersionInfo(interpreterPath);

public static Version VersionFromSysVersionInfo(string interpreterPath) {
Version version = null;
using (var output = ProcessOutput.RunHiddenAndCapture(
interpreterPath, "-c", "import sys; print('%s.%s' % (sys.version_info[0], sys.version_info[1]))"
)) {
output.Wait();
if (output.ExitCode == 0) {
var versionName = output.StandardOutputLines.FirstOrDefault() ?? "";
if (!Version.TryParse(versionName, out version)) {
version = null;
}
}
}
return version;
}

So yes, this error would also break that.

These types of errors from Conda usually indicate that it has been executed without activating it properly.

Now, previously, I have only seen this when importing some module that had a native dependency - so you could still run python.exe directly without activation. So the original logic for version detection did work.

It appears that, with Python 3.10, this is no longer the case, and the zlib dependency is directly from the DLL. So for 3.10+, python.exe in non-activated Conda environments is unusable. We'll either need to run the version-retrieval script in an activated environment, or figure out some other way of determining the version.

I looked into this more and I found a way to get the python version from a conda environment without activating it, but it requires a few more steps.

  1. Run conda list -n <env_name> python --json where <env_name> is the name of the environment.

This will output an array with a single element, which contains the python information, if the python package is installed.

{
    "base_url": "https://repo.anaconda.com/pkgs/main",
    "build_number": 3,
    "build_string": "h96c0403_3",
    "channel": "pkgs/main",
    "dist_name": "python-3.10.0-h96c0403_3",
    "name": "python",
    "platform": "win-64",
    "version": "3.10.0"
  }
  1. Now we can grab the version easy.

@AdamYoblick
Copy link
Member

@bschnurr Graham asked me to send the pylance issue your way, but this PR is broken right now because I pushed up code just to save my work, and it doesn't compile. Once I finish working on my p0 work, I'll get this PR in a healthy state, merge it in, then create separate issues for the debugger and pylance problems with 3.10 in conda and send you the pylance one 😄

@bschnurr
Copy link
Member

sure thing.

@bschnurr
Copy link
Member

got a popup when installing conda with python3.10
image

@AdamYoblick
Copy link
Member

Yeah this is expected until the linked PR gets merged in. This is because we try to call into python.exe in the conda environment to determine the python version, and this call crashes because of a conda bug with 3.10.

@AdamYoblick
Copy link
Member

@bschnurr The commit that fixes this problem is in the fix_python_310_detection branch, but hasn't been merged into main yet. If you want to fix it for yourself locally, cherry pick this commit into your local branch. That changes version detection logic for conda environments where python >= 3.10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants