2021年1月27日星期三

VSCode issue with Python versions and environments from Jupyter Notebooks

Issue: I am having issues with the environment and version of Python not matching the settings in VSCode, and causing issues with the packages I am trying to use in Jupyter notebooks. I am using a Windows 10 machine with Python 3.9.1 installed (including older versions), with Visual Studio Code 1.52.1 . Short summary - I install a package using pip. My guess is that it associates with the latest version of Python. I set up an interpreter in VS Code for that version of python, and try to import the package. The package is not found. If I call sys.version from the Jupyter notebook, I see that a default version of Python is running (3.8.5). The simple notebook throws an error because it cannot find that package that I installed with pip.

Screenshot that shows the associations: Screen capture from VSCode with annotations. import sys is circled in blue in the notebook, and an arrow follows that down to an output showing the print(sys.version) is 3.8.5 (default, Sep 3 2020, 21:29:08). Another blue arrow shows that the interpreter is set to Python 3.9.1. A set of red arrows shows the import pygmt command, with red arrows tracing that call to error ModuleNotFoundError: No module named 'pygmt'. Another red arrow shows that pygmt 0.2.1 is installed under a pip list command in terminal

This error is reproducible with only the

import pygmt  

command in the notebook, i.e. it does not depend on the other packages imported.

Question: How can I control the version that Jupyter notebooks will run in VSCode if changing the interpreter doesn't work? Every other issue like this that I have found was due to not choosing the correct interpreter. In this case, I have. Why is it not running that version of the interpreter?

Thank you.

https://stackoverflow.com/questions/65930454/vscode-issue-with-python-versions-and-environments-from-jupyter-notebooks January 28, 2021 at 11:03AM

没有评论:

发表评论