如何在运行 high Sierra 的 Mac 上告诉 VScode 使用哪个版本的 python [英] How to tell VScode, on my Mac running high Sierra, which version of python to use

查看:22
本文介绍了如何在运行 high Sierra 的 Mac 上告诉 VScode 使用哪个版本的 python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 VScode 编写和运行 python.我将它与 Jupyter 扩展一起使用.我有 2 个使用 Anaconda 创建的虚拟环境.一个 py27,用于 Python 2.7.13,另一个 py36,用于 Python 3.6.5.

I use VScode to write and run python. I use it with a Jupyter extension. I have 2 virtual environments created using Anaconda. One py27, for python 2.7.13 and the other, py36, for Python 3.6.5.

我有一个简单的代码,我将其编辑为仅在 python2 中运行.当我运行 VScode 时,我运行它的虚拟环境似乎无关紧要.VScode 似乎可以运行,但我不知道如何使它使用 py36(python 3.6.5)或 py27(python 2.7.13).

I have a simple code which I edited to only run in python2. When I run VScode, the virtual environment I run it in does not seem to matter. VScode seems to run but I can't figure out how to make it use py36 (python 3.6.5) or py27 (python 2.7.13).

通过在命令面板中使用不同的命令,或者双击 VScode 底部边框中的短语,我最终可以让它运行我想要的版本.但我还没有找到可重现的方法.

By using different commands in the command palette, or double-clicking on phrases in the bottom border of VScode I can eventually get it to run which version I want. But I have not found a reproducible method.

我已经尝试了大约 100 次,但都没有成功.我以为我找到了一种会重复的方法,但我又试了一次,但没有用.

I have tried about 100 times with no luck. I thought I found a method that would repeat but I tried it again and it didn't work.

我知道这个问题非常含糊,但要解释我尝试过的内容需要花费数页时间.我有大约 5 或 6 个设置,我尝试了多种组合.我尝试过的命令之一是选择一个 python 解释器.我有几种选择,但似乎都没有效果.此外,在 VScode 窗口的底部边框中,有一个特定的 Python 解释器的名称.你可以点击它来选择一个不同的 python 解释器.据我所知,这没有任何作用.实际上,这是一个障碍,因为用户可能认为他们实际上正在使用该解释器.

I know this question is very vague but it would take pages to explain what I've tried. I have about 5 or 6 settings which I've tried a plethora of combinations. One of the commands I tried is to select a python interpreter. I have several options but none seem to have an effect. Also, in the bottom border of the VScode window, there is the name of a specific python interpreter. You can click on this to select a different python interpreter. As far as I can tell this doesn't do anything. Actually, it's a hindrance because a user may think they are actually using that interpreter.

我尝试了 py27 和 p36,但没有任何区别.如果我可以让 Visual Studio 代码从 py27 开始,我可以将其更改为 py36 并返回到 py27.但是如何让它在 py27 中启动似乎是随机的.我的虚拟环境在我的主目录中,例如/User/myname/py27 以及 VScode 应用程序.

I've tried both py27 and p36 but I get no difference. If I can get visual studio code to start out in py27, I can make it change to py36 and back to py27. But how to make it start in py27 seems random. My virtual environments are in my home directory, /User/myname/py27 for example along with the VScode app.

推荐答案

https 上的文档://code.visualstudio.com/docs/python/environments 解释了如何选择您的虚拟环境.在不知道您安装虚拟环境的位置的情况下,我可以告诉您的最好方法是您可以手动指定要与 python.pythonPath 设置一起使用的解释器,或者如果您在工作区之外的目录中拥有两个虚拟环境文件夹,您可以使用 python.venvPath 设置指定公共文件夹.

The documentation at https://code.visualstudio.com/docs/python/environments explains how to select your virtual environment. Without knowing where you installed the virtual environments the best I can tell you is you can manually specify what interpreter to use with the python.pythonPath setting or if you have both virtual environments in a directory outside of your workspace folder you can specify the common folder with the python.venvPath setting.

这篇关于如何在运行 high Sierra 的 Mac 上告诉 VScode 使用哪个版本的 python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆