0


【pycharm】【配置Python解释器】【Configure a Python interpreter】

Configure a Python interpreter

配置Python解释器

Project interpreter:

File | Settings | Project: <project name> | Python Interpreter for Windows and Linux

PyCharm | Settings | Project: <project name> | Python Interpreter for macOS

Default project interpreter:

File | New Projects Setup | Settings for New Project for Windows and Linux

File | New Projects Setup | Preferences for New Project for macOS

项目解释器:文件|设置|项目名称:|适用于Windows和Linux的Python解释器PyCharm|设置|项目名称:|适用于macOS的Python解释器默认项目解释器:文件|新项目设置|用于Windows和LinuxFile的新项目的设置|新项目设置|MacOS新项目的首选项

1 Python interpreters in PyCharm

1 PyCharm中的Python解释器

To work with your Python code in PyCharm, you need to configure at least one Python interpreter. You can use a system interpreter that is available with your Python installation. You can also create a Virtualenv, pipenv, Poetry, or conda virtual environment. A virtual environment consists of a base interpreter and the installed packages.
要在PyCharm中使用Python代码,您需要配置至少一个Python解释器。您可以使用Python安装中提供的系统解释器。您还可以创建Virtualenv、pipenv、Poetry或conda虚拟环境。虚拟环境由基本解释器和已安装的软件包组成。

With PyCharm Professional, you can also configure interpreters to execute your Python code on remote environments by using SSH, Vagrant, Docker, Docker Compose, or WSL (only for Windows).
使用PyCharm Professional,您还可以配置解释器,通过使用SSH,Vagrant,Docker,Docker Compose或WSL(仅适用于Windows)在远程环境中执行Python代码。

When you configure a Python interpreter, you need to specify the path to the Python executable in your system. So, before configuring a Python interpreter, you need to ensure that you've downloaded Python and installed it in your system and you're aware of a path to it.
在配置Python解释器时,需要指定系统中Python可执行文件的路径。因此,在配置Python解释器之前,您需要确保已下载Python并将其安装在系统中,并且知道它的路径。

You can create several Python interpreters based on the same Python executable. This is helpful when you need to create different virtual environments for developing different types of applications. For example, you can create one virtual environment based on Python 3.6 to develop Django applications and another virtual environment based on the same Python 3.6 to work with scientific libraries.
您可以基于同一个Python可执行文件创建多个Python解释器。当您需要为开发不同类型的应用程序创建不同的虚拟环境时,这很有帮助。例如,您可以创建一个基于Python 3.6的虚拟环境来开发Django应用程序,并创建另一个基于相同Python 3.6的虚拟环境来使用科学库。

Python interpreters can be configured for a new project or for the current project (you can create a new interpreter or use one of the existing interpreters).
可以为新项目或当前项目配置Python解释器(您可以创建新解释器或使用现有解释器之一)。

2 Configuring an existing Python interpreter

2 配置现有的Python解释器

At any time, you can switch the Python interpreter either by using the Python Interpreter selector or in Settings.
在任何时候,您都可以通过使用Python解释器选择器或在设置中切换Python解释器。

2.1 Switch the Python interpreter using the Python Interpreter selector

2.1 使用Python解释器选择器切换Python解释器

  • The Python Interpreter selector is located on the status bar. It is the most convenient and quickest way to switch the Python interpreter. Just click it and select the target interpreter: Python解释器选择器位于状态栏上。这是切换Python解释器最方便、最快捷的方法。只需点击它并选择目标解释器:Project interpreter selector

2.2 Switch the Python interpreter in the IDE settings

2.2 在IDE设置中切换Python解释器

  1. Press CtrlAlt0S to open the IDE settings and then select Project <project name> | Python Interpreter. 按 Ctrl Alt 0S 打开IDE设置,然后选择项目|Python解释器。
  2. Click the drop-down and select the desired Python interpreter: 点击下拉菜单并选择所需的Python解释器:View interpreters
  3. If it's not on the list, click Show All. Then select the desired interpreter in the left pane and click OK. 如果不在列表中,请单击“全部显示”。然后在左窗格中选择所需的解释器并单击OK。When PyCharm stops supporting any of the outdated Python versions, the corresponding Python interpreter is marked as unsupported. 当PyCharm停止支持任何过时的Python版本时,相应的Python解释器被标记为不支持。

When you change the project interpreter and select an SSH interpreter, you might need to synchronize the local content with the target server. Mind a notification balloon in the lower-right corner:
当您更改项目解释器并选择SSH解释器时,可能需要将本地内容与目标服务器同步。注意右下角的通知气球:

Sync local files with the deployment server

You can choose to enable the automatic uploading of files to the server:
您可以选择启用自动上传文件到服务器:

  • Click Auto-upload files to start uploading on the next save. 单击“自动上载文件”,在下次保存时开始上载。
  • Click Sync and auto-upload files to immediately sync the files and upload them on every save in future. 单击“同步并自动上传文件”可立即同步文件并在以后每次保存时上传。

2.3 Modify a Python interpreter

2.3 修改Python解释器

  1. Press Ctrl Alt S to open the IDE settings and then select Project <project name> | Python Interpreter. 按 Ctrl Alt S 打开IDE设置,然后选择项目|Python解释器。
  2. Expand the list of the available interpreters and click Show All. 展开可用解释器的列表,然后单击全部显示。Show all available interpreters
  3. You can modify the path to the Python executable in the Interpreter path field. 您可以在解释器路径字段中修改Python可执行文件的路径。When the Associate this virtual environment with the current project checkbox is enabled, the interpeter is available only in the current PyCharm project. 当启用Associate this virtual environment with the current project复选框时,interpeter仅在当前PyCharm项目中可用。To change the interpreter name, select the target interpreter and click. 要更改解释器名称,请选择目标解释器并单击 。Edit iconThe Python interpreter name specified in the Name field, becomes visible in the list of available interpreters. Click OK to apply the changes. 在Name字段中指定的Python解释器名称在可用解释器列表中可见。单击确定以应用更改。Edit interpreter settings

2.4 Remove a Python interpreter

2.4 删除Python解释器

If you no longer need a Python interpreter for a project, you can remove it from the project settings.
如果你不再需要Python解释器,你可以从项目设置中删除它。

  1. Do one of the following: 执行以下操作之一:- Press Ctrl Alt S to open the IDE settings and then select Project <project name> | Python Interpreter. 按Ctrl Alt S 打开IDE设置,然后选择项目|Python解释器。- Click the Python Interpreter selector and choose Interpreter Settings. 单击Python解释器选择器并选择解释器设置。
  2. Expand the list of the available interpreters and click Show All. 展开可用解释器的列表,然后单击全部显示。Show all available interpreters
  3. Choose the interpreter that you want to remove and click .选择要删除的解释器,然后单击 。Remove a Python interpreter

3 Creating a new Python interpreter

3 创建一个新的Python解释器

Configuring local Python interpreters

配置本地Python解释器

To configure a local Python interpreter for the current project, follow one of the procedures below:
要为当前项目配置本地Python解释器,请执行以下步骤之一:

Configure a system interpreter

配置系统解释器

  1. Ensure that you have downloaded and installed Python on your computer. 确保你已经下载并安装了Python。 Installing Python on Windows from Microsoft Store 从Microsoft Store在Windows上安装Python
  2. Do one of the following: 执行以下操作之一:- Click the Python Interpreter selector and choose Add New Interpreter. 单击Python解释器选择器并选择添加新解释器。- Press CtrlAlt0S to open Settings and go to Project: <project name> | Python Interpreter. Click the Add Interpreter link next to the list of the available interpreters. 按 Ctrl Alt 0S 打开设置并转到项目:|Python解释器。单击可用解释器列表旁边的Add Interpreter链接。- Click the
标签: python pycharm ide

本文转载自: https://blog.csdn.net/wq6qeg88/article/details/136163979
版权归原作者 资源存储库 所有, 如有侵权,请联系我们删除。

“【pycharm】【配置Python解释器】【Configure a Python interpreter】”的评论:

还没有评论