You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

已安装Kivy仍提示‘No module named 'kivy'’的技术问题求助

Troubleshooting "ModuleNotFoundError: No module named 'kivy'" After Anaconda Installation

Hey there, this issue almost always comes down to mismatched Python environments—the environment where you installed Kivy via Anaconda isn’t the same one you’re using to run your code. Let’s fix this step by step:

1. Confirm Your Python Environment Match

First, let’s check which Python has Kivy installed, and which one your code is running on:

  • Open the Anaconda Prompt where you installed Kivy, then run these commands:
    # Check Python version
    python --version
    # Find Python executable path (Windows)
    where python
    # For macOS/Linux
    which python
    
  • Now open the terminal/editor you’re using to run your code (like VS Code’s terminal or system CMD) and run the same commands. If the version or path doesn’t line up, you’re using separate environments.

2. Run Your Script in the Correct Anaconda Environment

If you’re using an Anaconda virtual environment, activate it first before running your code:

# Replace "your_env_name" with your actual environment (e.g., base)
conda activate your_env_name
# Now run your script
python d:/Work/Porjects/Face Detector/appk.py

If you installed Kivy in the default base environment, just use the Anaconda Prompt directly to execute the run command above.

3. Point Your IDE to the Anaconda Python Interpreter

If you’re using an editor like VS Code or PyCharm, make sure it’s using the Anaconda Python that has Kivy:

  • VS Code: Click the Python version number in the bottom-left corner, then select the Anaconda Python path (e.g., C:\Users\YourName\anaconda3\python.exe or your virtual environment’s Python executable).
  • PyCharm: Go to File > Settings > Project: [Your Project Name] > Python Interpreter, click the gear icon, select Add, then navigate to your Anaconda Python path and select it.

4. Verify Kivy is Installed in the Target Environment

To double-check Kivy is present in the environment you’re using:
Activate the environment in Anaconda Prompt, then run:

# Check with pip (Windows)
pip list | findstr kivy
# For macOS/Linux
pip list | grep kivy
# Or check with conda
conda list kivy

You should see Kivy listed with a version number if it’s installed correctly.

Your Code for Reference

import kivy
from kivy.app import App
from kivy.uix.label import Label

class MyApp(App):
    def build(self):
        return Label(text="hello")

if __name__ == "__main__":
    MyApp().run()

Error Snippet

Traceback (most recent call last):
File "d:/Work/Porjects/Face Detector/appk.py", line 1, in
import kivy
ModuleNotFoundError: No module named 'kivy'

内容的提问来源于stack exchange,提问作者Muhammad Ansab

火山引擎 最新活动