为什么在VSCode终端上有特定的conda故障,而在普通终端上却没有? [英] Why is there a conda glitch specific to VSCode terminal, but not normal terminal?
问题描述
我使用的是Mac Catalina 10.15.7.Visual Studio代码版本:1.52.1
I am on a Mac Catalina 10.15.7. Visual Studio Code Version: 1.52.1
突然,我的conda环境无法在VSCode终端的激活环境中找到明显安装的熊猫(或任何其他)模块.
Suddenly, my conda environments are not able to find pandas (or any other) module that are clearly installed in the activated environments in the VSCode terminal.
下面,我向您展示VSCode中终端的输出.我已经激活了conda环境dm_assay.我展示了当我尝试安装熊猫时,上面写着已经安装".我列出了conda程序包,您可以在列表中看到熊猫.但是,当我打开python repl并导入熊猫时,我得到一个 ModuleNotFoundError:No Module named'pandas'
.昨天没有发生.
Below, I show you the output from the terminal in VSCode. I have already activated my conda environment, dm_assay. I show that when I try to install pandas, it says 'already installed'. I list the conda packages, and you can see pandas in the list. But when I open python repl and import pandas, I get a ModuleNotFoundError: No Module named 'pandas'
. This was not happening yesterday.
我打开了普通终端(不是VScode终端),做了同样的事情,现在熊猫导入了.(?)
I opened the normal terminal (not VScode terminal), and did the same thing, and now pandas import works. (?)
VSCode终端可能出了什么问题,从而阻止python访问活动conda env中的可用软件包?
在正常终端中,python路径会随着激活和停用conda envs而改变,但在VSCode终端中不会改变.
The python paths change with activating and deactivating conda envs in the normal terminals, but do not change in the VSCode terminal.
我尝试重新启动计算机.我想在VSCode中使用终端,因为它非常方便.两个终端都使用bin/zsh shell.
I have tried restarting my computer. I want to use terminal in VSCode as it is very convenient. Both terminals are using bin/zsh shell.
(dm_assay)me @ mycomp% conda install pandas
(dm_assay) me@mycomp % conda install pandas
Collecting package metadata (current_repodata.json): done
Solving environment: done
# All requested packages already installed.
(dm_assay)me @ mycomp% conda列表
(dm_assay) me@mycomp % conda list
# packages in environment at /usr/local/Caskroom/miniconda/base/envs/dm_assay:
#
# Name Version Build Channel
blas 1.0 mkl
ca-certificates 2021.1.19 hecd8cb5_0
certifi 2020.12.5 py38hecd8cb5_0
colorful 0.5.4 pypi_0 pypi
intel-openmp 2019.4 233
joblib 1.0.0 pyhd3eb1b0_0
libcxx 10.0.0 1
libedit 3.1.20191231 h1de35cc_1
libffi 3.3 hb1e8313_2
libgfortran 3.0.1 h93005f0_2
llvm-openmp 10.0.0 h28b9765_0
mkl 2019.4 233
mkl-service 2.3.0 py38h9ed2024_0
mkl_fft 1.2.0 py38hc64f4ea_0
mkl_random 1.1.1 py38h959d312_0
ncurses 6.2 h0a44026_1
numpy 1.19.2 py38h456fd55_0
numpy-base 1.19.2 py38hcfb5961_0
openssl 1.1.1i h9ed2024_0
pandas 1.2.1 py38hb2f4e1b_0
pip 20.3.3 py38hecd8cb5_0
prettyprinter 0.18.0 pypi_0 pypi
pygments 2.7.4 pypi_0 pypi
python 3.8.5 h26836e1_1
python-dateutil 2.8.1 py_0
pytz 2020.5 pyhd3eb1b0_0
readline 8.0 h1de35cc_0
scikit-learn 0.23.2 py38h959d312_0
scipy 1.6.0 py38h2515648_0
setuptools 51.1.2 py38hecd8cb5_4
six 1.15.0 py38hecd8cb5_0
sqlite 3.33.0 hffcf06c_0
threadpoolctl 2.1.0 pyh5ca1d4c_0
tk 8.6.10 hb0a8c7a_0
wheel 0.36.2 pyhd3eb1b0_0
xz 5.2.5 h1de35cc_0
zlib 1.2.11 h1de35cc_3
(dm_assay)me @ mycomp% python3
(dm_assay) me@mycomp % python3
Python 3.8.2 (default, Nov 4 2020, 21:23:28)
[Clang 12.0.0 (clang-1200.0.32.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pandas'
>>> quit()
(dm_assay)me @ mycomp% python3 --version
Python 3.8.2
(dm_assay) me@mycomp % python3 --version
Python 3.8.2
(dm_assay)me @ mycomp% conda --version
康达4.9.2
(dm_assay) me@mycomp % conda --version
conda 4.9.2
(dm_assay)me @ mycomp% pip --version
来自/usr/local/Caskroom/miniconda/base/envs/dm_assay/lib/python3.8/site-packages/pip(python 3.8)的pip 20.3.3
(dm_assay) me@mycomp % pip --version
pip 20.3.3 from /usr/local/Caskroom/miniconda/base/envs/dm_assay/lib/python3.8/site-packages/pip (python 3.8)
在VSCode中
(dm_assay)me @ mycomp% echo $ PATH
(dm_assay) me@mycomp % echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/Caskroom/miniconda/base/envs/dm_assay/bin:/usr/local/Caskroom/miniconda/base/condabin
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/Caskroom/miniconda/base/envs/dm_assay/bin:/usr/local/Caskroom/miniconda/base/condabin
(dm_assay)me @ mycomp% echo $ SHELL
/bin/zsh
(dm_assay) me@mycomp % echo $SHELL
/bin/zsh
(dm_assay)me @ mycomp项目%哪个python
(dm_assay) me@mycomp project % which python
/usr/bin/python
/usr/bin/python
在普通终端中
(dm_assay)me @ mycomp〜% echo $ PATH
(dm_assay) me@mycomp ~ % echo $PATH
/usr/local/Caskroom/miniconda/base/envs/dm_assay/bin:/usr/local/Caskroom/miniconda/base/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
/usr/local/Caskroom/miniconda/base/envs/dm_assay/bin:/usr/local/Caskroom/miniconda/base/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
(dm_assay)me @ mycomp〜% echo $ SHELL
(dm_assay) me@mycomp ~ % echo $SHELL
/bin/zsh
(dm_assay)me @ mycomp〜%哪个python
(dm_assay) me@mycomp ~ % which python
/usr/local/Caskroom/miniconda/base/envs/dm_assay/bin/python
/usr/local/Caskroom/miniconda/base/envs/dm_assay/bin/python
我注意到在普通终端中,当我激活和停用conda环境时,python路径(该python命令的输出)会改变.但是,在VSCode终端中,无论是否激活了conda env,python路径都保持相同(usr/bin/python).
I notice that in the normal terminal, the python path (output of which python command) changes when I activate and deactivate conda environments. However, in the VSCode terminal, the python path remains the same (usr/bin/python) no matter if a conda env is activated or not.
为什么conda在VSCode终端中不起作用?如何使它像普通终端一样工作?
Why isn't conda working in the VSCode terminal? How do I made it act like my normal terminal?
推荐答案
在VS Code中,它使用的内部终端是从系统自己的终端集成的.因此,如果可以使用系统终端,也可以使用VS Code的内部终端.
In VS Code, the internal terminal it uses is integrated from the system's own terminal. Therefore, if the system terminal can be used, the internal terminal of VS Code can also be used.
通常,当VS Code使用python环境时,模块存储在" lib \ site-packages
"目录中.对应的python环境.您可以使用命令" pip show pandas
"在VS Code终端中检查"pandas"模块的安装位置:
Usually, when VS Code uses the python environment, the modules are stored in "lib\site-packages
" of the corresponding python environment.
You could use the command "pip show pandas
" in the VS Code terminal to check the installation location of the module "pandas":
此外,建议您找到模块"pandas"的安装包.在这种环境下,然后尝试删除它并重新安装它,以避免由于模块内文件损坏或不兼容而引起的问题:
In addition, it is recommended that you find the installation package of the module "pandas" in this environment, and then try to delete it and reinstall it to avoid problems due to damaged or incompatible files inside the module:
如果仍然无法正常运行,请尝试重新启动VS Code,以使其重新加载终端.
If it still doesn't work, please try to restart VS Code to let it reload the terminal.
这篇关于为什么在VSCode终端上有特定的conda故障,而在普通终端上却没有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!