步骤 5:在 Python 环境中安装程序包Step 5: Install packages in your Python environment

03/09/2020

本文内容

Python 开发者社区制作了数千个有用的程序包,用户可以将它们合并到自己的项目中。The Python developer community has produced thousands of useful packages that you can incorporate into your own projects. Visual Studio 提供一个 UI,用于管理 Python 环境中的程序包。Visual Studio provides a UI to manage packages in your Python environments.

查看环境View environments

选择“视图” > “其他窗口” > “Python 环境”菜单命令 。Select the View > Other Windows > Python Environments menu command. “Python 环境” 窗口作为“解决方案资源管理器” 的同级打开,并向用户显示各种可用的环境。The Python Environments window opens as a peer to Solution Explorer and shows the different environments available to you. 列表中显示了使用 Visual Studio 安装程序安装的环境以及单独安装的环境。The list shows both environments that you installed using the Visual Studio installer and those you installed separately. 其中包括全局环境、虚拟环境和 conda 环境。That includes global, virtual, and conda environments. 粗体显示的环境是用于新项目的默认环境。The environment in bold is the default environment that's used for new projects.

备注

还可选择“解决方案资源管理器”窗口,再使用 Ctrl+K 或 Ctrl+` 键盘快捷方式打开“Python 环境”窗口。You can also open the Python Environments window by selecting the Solution Explorer window and using the Ctrl+K, Ctrl+` keyboard shortcut. 如果快捷方式不起作用,并且在菜单中找不到“Python 环境”窗口,则可能是你未安装 Python 工作负载。If the shortcut doesn't work and you can't find the Python Environments window in the menu, it's possible you haven't installed the Python workload.

通过环境的“概述” 选项卡,可以快速访问该环境的交互 窗口以及安装文件夹和解释器。The environment's Overview tab provides quick access to an Interactive window for that environment along with the environment's installation folder and interpreters. 例如,选择“打开交互窗口” ,会在 Visual Studio 中显示该特定环境的交互 窗口。For example, select Open interactive window and an Interactive window for that specific environment appears in Visual Studio.

现在,通过选择“文件” > “新建” > “项目”来创建新项目,然后选择“Python 应用程序”模板 。Now, create a new project with File > New > Project, selecting the Python Application template. 在随即出现的代码文件中,粘贴以下代码来创建像之前的教程步骤一样的余弦波,只不过这次以图形方式绘制。In the code file that appears, paste the following code, which creates a cosine wave like the previous tutorial steps, only this time plotted graphically. 或者,可使用之前创建的项目并替换代码。Alternatively, you can use the project you previously created and replace the code.

from math import radians

import numpy as np # installed with matplotlib

import matplotlib.pyplot as plt

def main():

x = np.arange(0, radians(1800), radians(12))

plt.plot(x, np.cos(x), 'b')

plt.show()

main()

打开 Python 项目后,还可右键单击 Python 环境,再选择“查看所有 Python 环境”,从解决方案资源管理器中打开“Python 环境”窗口With a Python project open, you can also open the Python Environments window from Solution Explorer by right-clicking Python Environments and selecting View All Python Environments

查看编辑器窗格,你会发现如果你将鼠标悬停到 numpy 和 matplotlib 上,会导入显示未解析的语句。Looking at the editor window, you'll notice that if you hover over the numpy and matplotlib import statements that they are not resolved. 这是因为尚未在默认全局环境中安装包。That's because the packages have not been installed to the default global environment.

使用“Python 环境”窗口安装包Install packages using the Python Environments window

在“Python 环境”窗口中,为新的 Python 环境选择默认环境,然后选择“包”选项卡。然后,你将看到环境中当前已安装的包的列表。From the Python Environments window, select the default environment for new Python projects and choose the Packages tab. You will then see a list of packages that are currently installed in the environment.

在搜索字段输入 matplotlib 的名称,再选择“运行命令: pip install matplotlib”选项来安装此项目 。Install matplotlib by entering its name into the search field and then selecting the Run command: pip install matplotlib option. 这将安装 matplotlib还将安装它依赖的所有包(在本例中,包含 numpy)。This will install matplotlib, as well as any packages it depends on (in this case that includes numpy).

如果系统提示同意提升,请同意。Consent to elevation if prompted to do so.

安装程序包后,它会显示在“Python 环境” 窗口中。After the package is installed, it appears in the Python Environments window. 单击程序包右侧的 X 可卸载它。The X to the right of the package uninstalls it.

备注

环境下方可能会出现一个小进度栏,指示 Visual Studio 正在为新安装的程序包生成 IntelliSense 数据库。A small progress bar might appear underneath the environment to indicate that Visual Studio is building its IntelliSense database for the newly-installed package. “IntelliSense” 选项卡也显示了更多详细信息。The IntelliSense tab also shows more detailed information. 请注意,完成该数据库之前,编辑器中的自动完成和语法检查等 IntelliSense 功能针对该程序包处于非活动状态。Be aware that until that database is complete, IntelliSense features like auto-completion and syntax checking won't be active in the editor for that package.

Visual Studio 2017 15.6 及更高版本采用不同且更快的方法来使用 IntelliSense,并在“IntelliSense”选项卡上显示一条简要介绍此内容的消息 。Visual Studio 2017 version 15.6 and later uses a different and faster method for working with IntelliSense, and displays a message to that effect on the IntelliSense tab.

运行程序Run the program

现已安装 matplotlib,请按 (F5) 运行项目来查看输出;如果没有调试器,则使用 (Ctrl+F5) :Now that matplotlib is installed, run the program with (F5) or without the debugger (Ctrl+F5) to see the output:

下一步Next step

深入了解Go deeper

如何装python软件_Visual Studio 中的 Python 教程步骤 5,安装包 | Microsoft Docs相关推荐

  1. visual studio可以开发python吗_Visual Studio上开发Python六大功能

    一.整合 Python 直译器 (Interpreter) & 互动视窗 (Interactive) Visual Studio 高度整合 Python 直译器,让您能够在开发过程中切换不同版 ...

  2. android studio调用python,Android studio中编写Python代码-2

    Chaquopy 教程 Chaquopy Chaquopy的作用:使用Chaquopy在Android Studio添加Python环境,java和Python互调 目前调试后APP可以正常运行(20 ...

  3. python之禅 中文_《Python之禅》中对于Python编程过程中的一些建议

    <Python之禅>中对于Python编程过程中的一些建议 来源:中文源码网    浏览: 次    日期:2018年9月2日 [下载文档:  <Python之禅>中对于Pyt ...

  4. 「Python」Terminal / cmd中的Python命令解释器中的pip操作

    查询pip版本 输入:python -m pip --version 升级pip 输入:python -m pip install --upgrade pip 安装pip 输入:python -m p ...

  5. visual studio 2022安装报错未能安装包“Microsoft.VisualStudio.Debugger.JustInTime.Msi,version=17.1.32112.364,ch

    问题: 未能安装包"Microsoft.VisualStudio.Debugger.JustInTime.Msi,version=17.1.32112.364,chip=x64". ...

  6. 解决docker容器中使用composer,无法解析安装包

    解决docker容器中使用composer,无法解析安装包 在laradock中进入容器,composer install -vvv出现了无法解析包的问题 // A code block Depend ...

  7. python软件使用_8家使用Python的世界一流软件公司

    python软件使用 There are over 500 current programming languages, with more being written every day. Admi ...

  8. python软件是免费的吗-Python编程软件下载

    Thonny是一款Python编程工具,非常适合Python的初学者使用,简单易操作,有错误的部分会直接显示出来,对于一些难懂的部分会给予解释,非常的人性化,需要的朋友欢迎下载使用. 软件优势 初始布 ...

  9. python软件开发的一般流程-Python各个岗位的开发流程

    根据张大美女提供资料微修改,在这谢谢张大美女! 1.python软件开发工程师 1.1 项目启动会 说明项目目标.阶段划分.组织结构.管理流程等关键事项. 1.2 需求调研 由用户提出,描述产品的功能 ...

最新文章

  1. 7个方面读懂6月的5G标准
  2. GOOGLE域名存在漏洞,可以用来建立钓鱼站点(目前已临时被封闭)
  3. BFS 保存路径模板
  4. boost::geometry::detail::overlay::get_relative_order用法的测试程序
  5. C#LeetCode刷题-剑指Offer
  6. Softmax回归概论
  7. IT公司速查手册的各大IT公司薪资和待遇内幕
  8. Flash存储的故事
  9. 西威变频器使用说明书_西威变频器说明书 (1)
  10. 本科毕业论文论文框架,可参考
  11. 【python入门第十六天】python数据类型-bytes
  12. 24考研数学复习方法、全年规划
  13. 重要更新|Amazon S3 和 CloudFront 已迁移至 Amazon Trust Services
  14. 计算机二级考试进制转换可以用计算机嘛,2016年计算机二级考试题中有关进制转换和编码问题...
  15. 区块链读书笔记01-区块链基础
  16. 正则匹配数字和字母php,用php与js实现正则匹配数字和字母组合的密码
  17. 穿戴式心电信号采集系统设计(任务书+lunwen+答辩PPt+查重报告)
  18. 关于Anaconda Navigator卡在Adding Featured Channels的解决办法
  19. Android(四十二):Drawable 转 Bitmap
  20. js图片上传(隐藏input file)

热门文章

  1. 视频直播APP开发的主要功能
  2. 临近算法knn(k-nearest neighbor)的计算
  3. 网易内推(Android) 拿offer
  4. 第四次团队作业——项目Alpha版本发布
  5. python 数值型字符串实现四舍五入 decimal_Python将科学计数法数值转换为指定精度浮点数...
  6. 喜讯 安超云正式成为“同心生态联盟”会员单
  7. Matlab如何打开新版本程序,求助:老程序在新版本的matlab中运行
  8. 全媒舍:基金牌照在企业宣传中所具有的作用大吗
  9. Cornerstone的分支问题Merge dry run failed: working copy is too old
  10. Django微信支付