有关在 Windows 上使用 Python 的常见问题解答Frequently Asked Questions about using Python on Windows

07/19/2019

本文内容

为什么我不能“pip 安装”某些包?Why can’t I “pip install” a certain package?

安装失败的原因有很多 - 在大多数情况下,正确的解决方案是联系包开发人员。There are a number of reasons why an installation will fail--in most cases the right solution is to contact the package developer.

出现问题的最常见原因是尝试将包安装到你无权修改的位置。The most common cause of problems is trying to install into a location that you do not have permission to modify. 例如,默认的安装位置可能需要管理权限,但是默认情况下,Python 没有管理权限。For example, the default install location might require Administrative privileges, but by default Python will not have them. 最佳解决方案是创建一个虚拟环境并在其中进行安装。The best solution is to create a virtual environment and install there.

某些包包括本机代码,需要 C 或 C++ 编译器才能进行安装。Some packages include native code that requires a C or C++ compiler to install. 一般来说,包开发人员应发布预编译的版本,但通常没有发布。In general, package developers should publish pre-compiled versions, but often do not. 如果安装了适用于 Visual Studio 的生成工具并选择了 C++ 选项,则某些包可能会正常运行,但是在大多数情况下,需要联系包开发人员。Some of these packages might work if you install Build Tools for Visual Studio and select the C++ option, however in most cases you will need to contact the package developer.

什么是 py.exe?What is py.exe?

由于要处理不同类型的 Python 项目,因此最终可能会在计算机上安装多个版本的 Python。You may end up with multiple versions of Python installed on your machine because you are working on different types of Python projects. 由于所有这些版本都使用 python 命令,因此你使用的是哪个版本的 Python 可能并不明显。Because these all use the python command, it may not be obvious which version of Python you are using. 作为标准,建议使用 python3 命令(或 python3.7 以选择特定版本)。As a standard, it is recommended to use the python3 command (or python3.7 to select a specific version).

py.exe 启动器将自动选择已安装的最新版本的 Python。The py.exe launcher will automatically select the most recent version of Python you've installed. 此外,还可以使用 py -3.7 之类的命令来选择特定版本,或者使用 py --list 来查看可使用的版本。You can also use commands like py -3.7 to select a particular version, or py --list to see which versions can be used. 但是,仅当使用从 python.org 安装的 Python 版本时,py.exe 启动器才会正常运行。从 Microsoft Store 安装 Python 时,不包含 py 命令。HOWEVER, the py.exe launcher will only work if you are using a version of Python installed from python.org. When you install Python from the Microsoft Store, the py command is not included. 对于 Linux、macOS、WSL 和 Microsoft Store 版本的 Python,应使用 python3(或 python3.7)命令。For Linux, macOS, WSL and the Microsoft Store version of Python, you should use the python3 (or python3.7) command.

为什么运行 python.exe 会打开 Microsoft Store?Why does running python.exe open the Microsoft Store?

为了帮助新用户找到正确的 Python 安装,我们向 Windows 添加了一个快捷方式,可直接转到 Microsoft Store 中发布的最新版本的社区包。To help new users find a good installation of Python, we added a shortcut to Windows that will take you directly to the latest version of the community's package published in the Microsoft Store. 该包无需管理员权限即可轻松安装,并将默认的 python 和 python3 命令替换相应的真实命令。This package can be installed easily, without administrator permissions, and will replace the default python and python3 commands with the real ones.

使用任何命令行参数运行快捷方式可执行文件都将返回错误代码,指示未安装 Python。Running the shortcut executable with any command-line arguments will return an error code to indicate that Python was not installed. 这是为了防止批处理文件和脚本意外打开 Store 应用。This is to prevent batch files and scripts from opening the Store app when it was probably not intended.

如果使用 python.org 中的安装程序安装 Python 并选择“添加到 PATH”选项,则新的 python 命令将优先于快捷方式。If you install Python using the installers from python.org and select the "add to PATH" option, the new python command will take priority over the shortcut. 请注意,其他安装程序可能以低于内置快捷方式的优先级添加 python__。Note that other installers may add python at a lower priority than the built-in shortcut.

通过从“开始”打开“管理应用执行别名”,找到“应用安装程序”Python 条目并将其切换为“关闭”,无需安装 Python 即可禁用快捷方式。You can disable the shortcuts without installing Python by opening "Manage app execution aliases" from Start, finding the "App Installer" Python entries and switching them to "Off".

当我复制粘贴文件路径时,为什么在 Python 中不起作用?Why don’t file paths work in Python when I copy-paste them?

Python 字符串对特殊字符使用“转义符”。Python strings use “escapes” for special characters. 例如,要在字符串中插入换行符,应键入 \n。For example, to insert a new line character into a string, you would type \n. 由于 Windows 上的文件路径使用反斜杠,因此某些部分可能已转换为特殊字符。Because file paths on Windows use backslashes, some parts might be being converted into special characters.

要将路径粘贴为 Python 中的字符串,请添加 r 前缀。To paste a path as a string in Python, add the r prefix. 这表示它是一个 raw 字符串,除 \” 外,将不使用任何转义字符(可能需要删除路径中的最后一个反斜杠)。This indicates that it is a raw string, and no escape characters will be used except for \” (you might need to remove the last backslash in your path). 因此,路径可能如下所示:r"C:\Users\MyName\Documents\Document.txt"So your path might look like: r"C:\Users\MyName\Documents\Document.txt"

在 Python 中使用路径时,建议使用标准 pathlib 模块。When working with paths in Python, we recommend using the standard pathlib module. 这样你就可以将字符串转换为丰富的 Path 对象,无论它使用正斜杠还是反斜杠,都可以一致地进行路径操作,从而使代码在不同的操作系统上可以更好地工作。This will let you convert the string to a rich Path object that can do path manipulations consistently whether it uses forward slashes or backslashes, making your code work better across different operating systems.

什么是 PYTHONPATH?What is PYTHONPATH?

Python 使用 PYTHONPATH 环境变量来指定可以从中导入模块的目录列表。The PYTHONPATH environment variable is used by Python to specify a list of directories that modules can be imported from. 运行时,可以检查 sys.path 变量以查看导入某些内容时将要搜索的目录。When running, you can inspect the sys.path variable to see which directories will be searched when you import something.

要在“命令提示符”中设置此变量,请使用:set PYTHONPATH=list;of;paths。To set this variable from the Command Prompt, use: set PYTHONPATH=list;of;paths.

要在 PowerShell 中设置此变量,请在启动 Python 之前使用:$env:PYTHONPATH=’list;of;paths’。To set this variable from PowerShell, use: $env:PYTHONPATH=’list;of;paths’ just before you launch Python.

不建议通过“环境变量”设置全局设置此变量,因为使用它的可能是任何版本的 Python,而非要使用的版本********。Setting this variable globally through the Environment Variables settings is not recommended, as it may be used by any version of Python instead of the one that you intend to use.

何处可以找到有关打包和部署的帮助?Where can I find help with packaging and deployment?

Docker:VSCode 扩展有助于快速打包和部署 Dockerfile 和 docker-compose.yml 模板(为项目生成正确的 Docker 文件)。Docker: VSCode extension helps you quickly package and deploy with Dockerfile and docker-compose.yml templates (generate the proper Docker files for your project).

借助 Azure Kubernetes 服务 (AKS),可以在按需缩放资源的同时部署和管理容器化应用程序。Azure Kubernetes Service (AKS) enables you to deploy and manage containerized applications while scaling resources on demand.

如果需要在不同的计算机上工作,该怎么办?What if I need to work across different machines?

通过设置同步,可以使用 GitHub 在不同安装之间同步 VS Code 设置。Settings Sync allows you to synchronize your VS Code settings across different installations using GitHub. 如果在不同的计算机上工作,这有助于在它们之间保持一致的环境。If you work on different machines, this helps keep your environment consistent across them.

如果我习惯使用 PyCharm、Atom、Sublime Text、Emacs 或 Vim,该怎么办?What if I'm used to using PyCharm, Atom, Sublime Text, Emacs, or Vim?

VSCode 扩展键映射有助于打造你熟悉的环境。The VSCode extension Keymaps can help your environment feel right at home.

如何将 Mac 快捷键映射到 Windows 快捷键?How do Mac shortcut keys map to Windows shortcut keys?

Windows 计算机和 Macintosh 的某些键盘按钮和系统快捷方式略有不同。Some of the keyboard buttons and system shortcuts are slightly different between a Windows machine and a Macintosh.

python3安装常见问题_有关在 Windows 上使用 Python 的常见问题解答相关推荐

  1. 有关在 Windows 上使用 Python 的常见问题解答

    使用 pip install 解决包安装问题 安装失败的原因有很多 - 在很多情况下,正确的解决方案是联系包开发人员. 出现问题的常见原因是尝试将包安装到你无权修改的位置. 例如,默认的安装位置可能需 ...

  2. python windows 客户端开发_如何在Windows上使用Python进行开发

    本文由葡萄城技术团队于原创并首发 转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 一直以来C#都是微软在编程语言方面最为显著的Tag,但时至今日Python ...

  3. asp.net web开发步骤_如何在Windows上做Python开发?微软出了官方教程

    机器之心报道 参与:路 在 Windows 上做 Python 开发太痛苦?微软最近发布了一系列官方教程,终于-- 教程地址:https://docs.microsoft.com/zh-cn/wind ...

  4. python联想_联想电脑python安装教程_如何在windows上安装python

    如何在windows上安装python 方法如下: 首根据Windows版本(64位32位)从Python的官方网站下载Python 3.5的64装程序或32位安装程序. 然后,运行下载的EXE安装包 ...

  5. ubuntu安装python_使用WSL在Windows上搭建Python开发环境

    简介 2016年,微软推出了Windows Subsystem for Linux(WSL),这使得Windows具有了强大的Unix功能.2019年5月,微软宣布发布了具有更新架构的WSL2,该架构 ...

  6. python可以调用windows资源吗_如何在Windows上用Python调用WinRar?还有问题吗

    使用zipfile模块,我创建了一个脚本来提取我的归档文件,但是这个方法会破坏除txt文件之外的所有内容.在def unzip(zip): filelist = [] dumpfold = r'M:\ ...

  7. python:在Windows上使用 Python

    python:在Windows上使用 Python 4.1. 完整安装程序 4.2. Microsoft Store包 4.3. nuget.org 安装包 4.4. 可嵌入的包 4.5. 替代捆绑包 ...

  8. 怎么在电脑上使用python-开始在 Windows 上使用 Python(初学者)

    开始在 Windows 上使用 Python(初学者)Get started using Python on Windows for beginners 07/19/2019 本文内容 下面是一个分步 ...

  9. 如何在电脑上使用python-如何在Windows上使用Python进行开发

    本文由葡萄城技术团队于原创并首发 转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 一直以来C#都是微软在编程语言方面最为显著的Tag,但时至今日Python ...

最新文章

  1. 头条面试归来,有些话想和Java程序员说!
  2. 还在为投文章发愁吗,也许你更适合审别人的文章——JGG期刊专职编辑招聘(IF4)...
  3. Android开机画面~(自己还没试验)
  4. linux+expect插件_Linux批量部署工具Expect
  5. ecshop属性排序
  6. 研究生信息管理系统(C++实现)
  7. android studio for android learning (十八) android事件监听器绑定的方法详解
  8. 屏幕距离和坐便转换工具_简单好用的视频分辨率转换器推荐
  9. Code.V光学设计学习(一)——入门介绍
  10. 计算机条件格式设置方法,excel怎样利用条件格式把
  11. 支付宝提示服务器有【中危漏洞】任意邮件伪造检测
  12. 多读书,更要多多悦读
  13. 2.服务器部署web服务器
  14. Android手机中的加速度计与陀螺仪
  15. 【RSA原理5】浅谈--密钥如何生成及其可靠性说明
  16. 用origin画统计图
  17. 涉密网络中使用的计算机,涉密场所中连接互联网的计算机可以安装和使用摄像头。()...
  18. mblock编程思维开发,自制糖豆人小游戏
  19. 3D游戏 java_基于Java的开源3D游戏引擎jMonkeyEngine
  20. 阿里巴巴大数据之路-元数据

热门文章

  1. cve-2022-22965是什么,一个至少超越我此刻理解力的漏洞
  2. sqlmap地表最强sql注入检测工具学习使用
  3. windbg调试windows下的程序
  4. python can i use return in wiht statement?
  5. zoho配置dmarc_停止[营销]电子邮件反弹! 如何配置SPF,DMARC和DKIM
  6. 数据科学基础_学习数据科学基础
  7. 拼图登陆拼图二维码验证_如何使用拼图快速轻松地构建静态网站
  8. fx系列微型可编程控制器 通信_AB罗克韦尔自动化Micro870可编程逻辑控制器系统型号及功能介绍...
  9. selenium的页面等待
  10. 数据库查询:列出各个部门中工资高于本部门平均工资的员工信息,并按部门号排序。