Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

conda - VSCode is running two different versions of Python - one for environment and one for system

Screen Capture of VSCode showing version of Python is different in the selected Python interpreter than what sys.version calls from the code snippetI am trying to create geographical maps of data, and to do this I am trying to use the basemap package. As I was using Python 3.9 on Windows 10, installing basemap was nearly impossible. So I created a new environment running Python 3.6, which allowed me to install basemap with no issues. Now basemap shows up under conda list command, and my new environment py36 is selectable in VSCode. Once selected, it tells me I am using Python 3.6.12. However, when I simply try to import packages:

    %matplotlib inline
    import numpy as np
    import matplotlib.pyplot as plt
    #import basemap
    import sys
    print(sys.version)  

...basemap cannot be imported. (It is commented out in this version so that I could print the version of Python that was running in VSCode). So I commented the import basemap line out (all other packages imported correctly) and added two lines to print the version of Python that the code snippet was using. The result was surprising: Despite selecting an interpreter that was using 3.6.12 (see image attached, bottom of screen shot), the return for print(sys.version) was

    3.9.1 (tags/v3.9.1:1e5d33e, Dec  7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)]

How can I get VSCode to run the version of Python that is defined explicitly in the environment, so that I can import basemap?

Thank you in advance for any help on the subject.

Brad

question from:https://stackoverflow.com/questions/65867761/vscode-is-running-two-different-versions-of-python-one-for-environment-and-one

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...