简体   繁体   中英

Python environment different between terminal and VSCode

I am having issues using my conda environment from within VS Code. This is strange because it has usually worked in the past but recently not anymore. I read through some posts to find a solution but was unable to solve it.

I am trying to use a conda environment called jobapp .

In terminal:

(base)
User in JobApp $ conda activate jobapp

(jobapp) 
User in JobApp $ which python
/Users/User/opt/anaconda3/envs/jobapp/bin/python

In VSCode:

(base) 
User in jobapp $ conda activate jobapp

(jobapp) 
User in jobapp $ which python
/usr/bin/python

So even though the (jobapp) indicator is making it look like the environment is active, the python path is still wrong.

How can I make it so it works the same as the terminal?

In VS code, you can change the python interpreter by press Ctrl + Shit + P , then set the path to the chosen python interpreter as /path_to_your/python , if you are using jupyter notebook, you should select which kernel your jupyter notebook is using by press Ctrl + Shit + P or F1 , then type and choose Jupyter: Filter kernels , you will see a box pops up, only tick the virtual environment python interpreter you want to use and untick other python interpreters.

After this step, press Ctrl + Shit + P or F1 , then type and choose Developer: Reload Window , then your choice of the previous step will be loaded, and only one python interpreter (ie the one in the virtual environment) will be used.

If this still not works. It may be because the current jupyter extension seems to have problems with the kernel/python interpreter selection. Uninstall the current version and install a previous version, say 6 month ago.

Please keep me updated whether this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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