Visual Studio 2017 中的 Python 3.6 如何在交互式 Shell 中运行程序 [英] Python 3.6 in Visual Studio 2017 How to Run Program in the Interactive Shell

查看:30
本文介绍了Visual Studio 2017 中的 Python 3.6 如何在交互式 Shell 中运行程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载并安装了 Visual Studio 和 Anaconda,以访问 Anaconda 预安装的所有软件包.我试图弄清楚如何运行代码,使其在交互式 shell 中运行.现在,当我按 F5 时,Anaconda 3 cmd 行窗口会出现提示按任意键继续...".我的问题是:我怎样才能做到当我按下 F5 时,我的代码在交互式 Python shell 中执行,就像在 Python 附带的基本 IDLE 上执行的一样.

I downloaded and installed Visual Studio along with Anaconda to get access to all of the packages that come pre installed with Anaconda. I am trying to figure out how to run code such that it runs in the interactive shell. Right now when I hit F5 an Anaconda 3 cmd line window comes up with the prompt "Press any key to continue..." comes up. My question is: how can I make it so that when I hit F5 my code is executed in the interactive Python shell much like it does on the basic IDLE that comes with Python.

这似乎是一个简单的 Google 搜索就可以解决的问题,但由于某种原因我找不到答案.我做了一些谷歌搜索,并观看了有关它的 Visual Studio python 官方 Microsoft 系列.其中一个视频涉及使用交互式 shell,但即使在视频中,当他单击开始(运行)"按钮时,代码也在命令行中运行.

This seems like a question that a simple Google Search could fix, but for some reason I cannot find the answer. I've done some google searching, and I watched the Visual Studio python official Microsoft series about it. One of the videos touched on using the interactive shell, but even in the video, when he clicked the Start (Run) button, the code ran in what looked like the command line.

我过去使用过 IDLE,现在我认为是时候改用更大的 IDE.我喜欢 Visual Studio 的代码完成和模板,我迫不及待地想解决这个(菜鸟)问题.

I have used IDLE in the past, and now I think it is time to make the change to a bigger IDE. I love the code completion and templates of visual studio, and I can't wait to solve this (noob) question.

谢谢

推荐答案

我也在为此苦苦挣扎.有一个 Visual Studio Shell 命令 execute file in Python interactive 绑定到 Shift+Alt+F5默认.

I am struggling with this as well. There is a Visual Studio Shell command execute file in Python interactive which is bound to Shift+Alt+F5 by default.

这是有效的:如果焦点在代码窗口中,则执行当前文件.如果焦点位于解决方案资源管理器 窗口中,则执行选择为启动项"的文件.然而,似乎有一个小故障:来自特定文件的一些导入语句在标准 Ctrl+F5 上运行良好,在 Shift+ 上将失败Alt+F5.我需要弄清楚为什么会这样,并会在此处报告.

This works: if the focus is in a code window then the current file is executed. If the focus is in the Solution Explorer window, the file selected as "Startup item" is executed. There seems to be a glitch however: Some import statements from the specific file which work fine on the standard Ctrl+F5 will fail on Shift+Alt+F5. I need to figure out why this is the case and will report here.

进入交互式窗口后,将工作目录更改为包含项目的文件夹:os.chdir 等.然后 import your-filename 完美运行.所以我假设在执行 Shift+Alt+F5 时选择工作目录存在一些问题.

Once in the interactive windows, change the working directory to the folder containing the project: os.chdir etc. Then import your-filename works flawlessly. So I assume that there is some problem with selecting the working directory while executing Shift+Alt+F5.

这篇关于Visual Studio 2017 中的 Python 3.6 如何在交互式 Shell 中运行程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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