简体   繁体   English

VSCode中的Python路径

[英]Python path in VSCode

I have an Anaconda distribution installed on Mac OSX (10.14.2). 我在Mac OSX(10.14.2)上安装了Anaconda发行版。 With it, I installed VSCode which I'm to write python scripts. 有了它,我安装了VSCode来编写python脚本。 Recently, I've updated some environments in Anaconda and something happened with the configuration of the python path VSCode uses for its integrated terminal: when I run my code, an ImportError comes up for the joblib package that I now have installed in my conda environment (also happens for other packages), which doesn't happen when I run the same code in a regular terminal. 最近,我在Anaconda中更新了一些环境,并且VSCode用于其集成终端的python路径的配置发生了一些事情:当我运行代码时,针对我现在安装在conda环境中的joblib软件包出现ImportError (其他软件包也是如此),当我在常规终端中运行相同的代码时不会发生这种情况。

Using conda list in the integrated terminal gives me the correct list of packages for the environment I'm using, and conda env list indicates that indeed this specific environment should be active. 在集成终端中使用conda list为我使用的环境提供正确的软件包列表,而conda env list则表明确实应该激活此特定环境。 However, I can see that that something is off, because in my normal terminal I get: 但是,我可以看到有些问题,因为在我的普通终端中,我得到了:

$ which python
python is /Users/Joris/anaconda3/envs/astro3/bin/python
python is /usr/bin/python

While in the VSCode terminal: 在VSCode终端中:

$ which python
python is /usr/bin/python
python is /Users/Joris/anaconda3/envs/astro3/bin/python

I've tried changing some of the VSCode settings, like manually pointing python.pythonPath and python.venvPath to my anaconda environment folders. 我尝试更改某些VSCode设置,例如手动将python.pythonPathpython.venvPath指向我的anaconda环境文件夹。 (The setting python.terminal.activateEnvironment is set to true.) Also, reinstalling VSCode through the Anaconda distribution does not seem to help. (设置python.terminal.activateEnvironment设置为true。)此外,通过Anaconda发行版重新安装VSCode似乎没有帮助。 So unfortunately, I can't seem to get VSCode to run python with my Anaconda environment which contains the packages I need. 因此,不幸的是,我似乎无法让VSCode在包含所需软件包的Anaconda环境中运行python。

  1. Press (macOS): + + P , (Linux/Windows: Ctrl + Shift + P ) in VS Code. 在VS Code中按(macOS): + + P (Linux / Windows: Ctrl + Shift + P )。
  2. Type: python select interpreter 类型: python select interpreter
  3. Select /Users/Joris/anaconda3/envs/astro3/bin/python 选择/Users/Joris/anaconda3/envs/astro3/bin/python
  4. Test if your lib is usable. 测试您的lib是否可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM