2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > python3安装常见问题_有关在 Windows 上使用 Python 的常见问题解答

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

时间:2018-09-05 20:53:51

相关推荐

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

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

07/19/

本文内容

为什么我不能“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 版本时,py.exe 启动器才会正常运行。从 Microsoft Store 安装 Python 时,不包含 py 命令。HOWEVER, the py.exe launcher will only work if you are using a version of Python installed from . 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 并选择“添加到 PATH”选项,则新的 python 命令将优先于快捷方式。If you install Python using the installers from 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.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。