You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python新手求助:已安装pypresence仍触发ModuleNotFoundError

Fixing ModuleNotFoundError: No module named 'pypresence' Even After Installation

Hey there! I get it, it's super frustrating when you install a package like you're supposed to, but your code still throws a module not found error. Let's break down the most common reasons this happens and how to fix them step by step.

First, let's recap your code for reference (I cleaned it up a bit for readability):

from pypresence import Presence
import time

client_id = '...'  # Don't forget to replace this with your actual Discord client ID!
RPC = Presence(client_id)
RPC.connect()

print(RPC.update(
    state="Lookie Lookie",
    details="A test of qwertyquerty's Python Discord RPC wrapper, pypresence!"
))

while True:
    time.sleep(15)

Common Causes & Solutions

1. You're using a different Python version than the one you installed pypresence to

This is by far the most common issue. If your system has multiple Python versions (like Python 2 and 3), pip might be installing the package for one version, but you're running your code with another.

  • Fix: Use version-specific pip and python commands:
    • Install with pip3 install pypresence (for Python 3, which is the version you should be using)
    • Run your script with python3 your_script_name.py

To check which Python version you're using, run python --version or python3 --version in your terminal.

2. You're working in a virtual environment, but installed the package globally

If you set up a virtual environment for your project (like venv or conda), packages installed with regular pip go to your global Python installation—not the virtual environment your code is running in.

  • Fix:
    1. Activate your virtual environment first:
      • On Windows: venv\Scripts\activate
      • On macOS/Linux: source venv/bin/activate
    2. Then run pip install pypresence again while the environment is active.

3. The package isn't installed in a directory Python checks for modules

Sometimes, pip installs packages to a location that isn't in your Python's module search path. Let's verify this:

  • First, check where pypresence is installed:

    pip show pypresence
    

    Look for the Location line in the output.

  • Then, check which directories Python looks for modules in:

    import sys
    print(sys.path)
    

    Run this in the same Python environment you're using to run your script.

If the Location from pip show isn't in the sys.path list, try these fixes:

  • Reinstall the package using the --user flag (installs to your user directory, which is almost always in sys.path):
    pip install --user pypresence
    
  • Or, manually add the installation directory to sys.path at the top of your script (a quick, temporary fix):
    import sys
    sys.path.append("/path/to/pypresence/location")  # Replace with your actual path from pip show
    from pypresence import Presence
    # Rest of your code...
    

4. Permission issues (Windows/macOS/Linux)

On some systems, you might not have permission to install packages to the global Python directory. Using the --user flag (mentioned above) fixes this by installing to your user-specific directory instead of the system-wide one.

For Linux/macOS, avoid using sudo pip install unless absolutely necessary—it can mess up your system Python installation.


Once you try these steps, your script should be able to find the pypresence module. Double-check that you've replaced '...' with your actual Discord client ID too!

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 06:47:29