簡體   English   中英

Visual Studio Code - 交互式 window:即使安裝了 jupyter,更改環境也不起作用

[英]Visual Studio Code - Interactive window: changing the environment does not work even with jupyter installed

我的問題是這樣的: 你如何在 Vscode 上改變 Python Interactive 的環境? ,但提供的解決方案似乎對我不起作用。

我在 Ubuntu 20.10 上,使用從 snap 商店安裝的 Visual Studio Code 1.53.2。

為了調試它,我使用 conda 從頭開始重新創建了我的環境:

name: mytrips

channels:
  - defaults
  - conda-forge

dependencies:
  - python=3.8.*
  - pip

  - numpy==1.19.*
  - pandas==1.2.*
  - cartopy==0.18.*
  - jupyterlab

(我已經把jupyterlab放在那里,所以它應該具有交互式窗口所需的所有依賴項)。

在左下角,解釋器正確設置為環境“mytrips”。 我正在使用僅包含以下兩行的測試腳本:

import cartopy


print(cartopy.__version__)

當我右鍵單擊並 select “在終端中運行 python 文件”時,這就是(正確)發生的情況:

source /home/rick/anaconda3/bin/activate
(base) rick@linux:~/Documents/src/My trips$ source /home/rick/anaconda3/bin/activate
(base) rick@linux:~/Documents/src/My trips$ conda activate mytrips
(mytrips) rick@linux:~/Documents/src/My trips$ /home/rick/anaconda3/envs/mytrips/bin/python "/home/rick/Documents/src/My trips/test.py"
0.18.0

所以你可以在這里看到cartopy是正確導入的。

當我按 shift+Enter 或右鍵單擊 select 以在交互式 window 中運行當前文件時,它返回ModuleNotFoundError: No module named 'cartopy' ,因為它使用來自基本 conn環境的 Z23EEEB4347BDD26BFC6B7EE9A3B7。 問題 1:我的環境中有 jupyter,但它的行為就好像它沒有被檢測到一樣。

然后,當我單擊mytrips環境中的交互式 window 和 select 的右上角時,交互式 Window 會打印出來,就好像它剛剛更改了環境一樣:

Started 'Python 3' kernel
Python 3.8.6 (default, Sep 25 2020, 09:36:53) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.20.0 -- An enhanced Interactive Python. Type '?' for help.

但仍然無法導入cartopy ,如果我檢查 Interactive Window 它現在使用的是什么可執行文件,結果是:

import sys
sys.executable
'usr/bin/python3'

這就是問題 2:交互式 Window 實際上並沒有改變我的環境。

只是為了確認,這里證明環境有jupytercartopy

(mytrips) rick@linux:~/Documents/src/My trips$ conda list | grep jupyter
jupyter_client            6.1.7                      py_0  
jupyter_core              4.7.1            py38h06a4308_0  
jupyterlab                2.2.6                      py_0  
jupyterlab_pygments       0.1.2                      py_0  
jupyterlab_server         1.2.0                      py_0  
(mytrips) rick@linux:~/Documents/src/My trips$ conda list | grep ipython
ipython                   7.20.0           py38hb070fc8_1  
ipython_genutils          0.2.0              pyhd3eb1b0_1 
(mytrips) rick@linux:~/Documents/src/My trips$ conda list | grep cartopy
cartopy                   0.18.0           py38h0d9ca2b_1

關於發生了什么的任何提示?

似乎是最近在 VSCode-Jupyter github 上已經存在幾個問題的問題。 主線是下面的鏈接。 我還在此鏈接中評論了我的解決方法。

https://github.com/microsoft/vscode-jupyter/issues/4831

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM