简体   繁体   English

PyCharm ModuleNotFoundError: No module named 'turtle'

[英]PyCharm ModuleNotFoundError: No module named 'turtle'

I am new to programming and wanted to use turtle in PyCharm (Community Edition 2020.3).我是编程新手,想在 PyCharm(社区版 2020.3)中使用海龟。 I am running Pop-OS 20.10.我正在运行 Pop-OS 20.10。

This is what I entered:这是我输入的:

import turtle
s = turtle.getscreen()

This is what I got from PyCharm:这是我从 PyCharm 得到的:

Traceback (most recent call last):
    File "/home/przvl/PycharmProjects/Introduction/Turtle Car.py", line 3, in <module>
      import turtle
ModuleNotFoundError: No module named 'turtle'

I installed tkinter with:我安装了 tkinter :

sudo apt install python3-tk

I can run turtle from the CLI:我可以从 CLI 运行 turtle:

在 CLI 中运行的海龟

PyCharm is set to the correct Python interpreter (as far as I know): PyCharm 设置为正确的 Python 解释器(据我所知):

PyCharm 解释器设置

Your interpreter settings show you did not installed turtle in the virtual environment that Pycharm is configured to work with.您的解释器设置显示您没有在 Pycharm 配置使用的虚拟环境中安装turtle。

Two options:两种选择:

  1. Recommended - install `turtle' on the venv (u can just "+" in the pycharm)推荐 - 在 venv 上安装“turtle”(你可以在 pycharm 中只使用“+”)
  2. Configure Pycharm to work with your system python to where you have probably installed turtle.配置 Pycharm 以使用您的系统 python 到您可能安装了 turtle 的位置。

I ended up downloading PyCharm from jetbrains.com and manually installing it via the CLI.我最终从 jetbrains.com 下载 PyCharm 并通过 CLI 手动安装它。 The interpreter now works correctly and I can use turtle.解释器现在可以正常工作,我可以使用 turtle。

Previously, I used Pop-OS inbuilt Shop and flatpak installation of the program, which seems to cause trouble for some users.之前我用的是Pop-OS内置的Shop和flatpak安装的程序,这似乎给一些用户带来了麻烦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM