# Fix "ModuleNotFoundError: No module named 'slackclient'" by Porting a Bot to slack_sdk

Yes. An agent pins the error to the 2.0 rename of the slackclient package, ports the bot to slack_sdk, and shows it reaching Slack's auth check.

[Run this on Rush](https://cloud.getrush.ai/run/fix-no-module-named-slackclient/slackclient/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

`slackclient` 2.0.0 kept its name on PyPI and changed the name you import: the package installs as `slack`, and `from slackclient import SlackClient` fails with the ModuleNotFoundError in the title even though `pip` reports the install succeeded. The 2.x line ended at 2.9.4 in 2022, and importing it prints `UserWarning: slack package is deprecated. Please use slack_sdk.web/webhook/rtm package instead`. So a bot written against 1.x breaks the first time it is installed without a pin, and the install itself gives no hint.

A bot like mattmakai/slack-starterbot shows the whole surface in one file. `requirements.txt` says `slackclient>=1.1.0`, which resolves to 2.9.4 today, and `starterbot.py` opens with `from slackclient import SlackClient` on line 4. The rest of the file is the 1.x RTM loop: `SlackClient(os.environ.get('SLACK_BOT_TOKEN'))`, `rtm_connect(with_team_state=False)`, `api_call("auth.test")["user_id"]` to learn the bot's own id, then a `while True` that calls `rtm_read()` every `RTM_READ_DELAY` second, matches `MENTION_REGEX` against each message, and answers through `api_call("chat.postMessage", channel=channel, text=...)`. The README is three lines pointing at the tutorial the file came from.

The agent installs the file as written in a clean environment, runs the bot and quotes the traceback. Then it checks the quick fix in a second environment: `pip install "slackclient<2"` gives 1.3.2 with websocket-client 0.54.0, the import works on Python 3.11, and with a token in the environment the script runs until Slack refuses the connection with `slackclient.server.SlackLoginError`. That proves the pin restores the old code path, and also that the old library has had no release since 2019, which is the case for porting rather than pinning.

The port goes to `slack_sdk`, the maintained successor. `WebClient` replaces `SlackClient` for every `api_call`: `auth_test()` returns the bot's user id and `chat_postMessage(channel=..., text=...)` sends the reply, with a `SlackApiError` instead of a dictionary when Slack says no. The agent checks each method name against the installed package rather than from memory. For the event loop it reads the app's configuration: the RTM API the old code used is available only to classic Slack apps, so a bot that still has a classic app keeps the loop through `slack_sdk.rtm_v2.RTMClient`, and one on a current app moves to `SocketModeClient` with an app-level token and the Events API. The agent writes the port for the kind of app the repository describes, runs it with a placeholder token to show it reaches Slack's auth check, and leaves the real token out of the sandbox.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "This Slack bot fails with ModuleNotFoundError: No module named 'slackclient'. In a clean virtual environment install the project exactly as its requirements say, run it and quote the traceback with the resolved slackclient version. In a second environment install slackclient below 2.0 and report whether the import and the connect call work, and when that line last had a release. Then port the bot to slack_sdk: WebClient for every api_call, with the exact method names checked against the installed package, and SlackApiError handling where the old code read a response dictionary. For the event loop, read the repository and its README to decide whether this is a classic app that can keep RTM through slack_sdk.rtm_v2 or a current app that needs Socket Mode with an app-level token and the Events API; say which you chose and why, and list the scopes and tokens the new version needs. Pin slack_sdk in requirements.txt. Run the ported bot with a placeholder token and show that it stops at Slack's auth error rather than at an import or attribute error. Do not commit any token. Open a pull request with the port, the two environment reports and the setup steps a maintainer must do in the Slack app configuration.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

A pull request that rewrites the bot module and replaces the `slackclient` line in `requirements.txt` with a pinned `slack_sdk`. The description starts with the two environments: the 2.9.4 install and its traceback, then the 1.3.2 install that imports but belongs to a line last released in 2019. A table maps each old call to its new form, `SlackClient` to `WebClient`, `api_call("chat.postMessage", ...)` to `chat_postMessage(...)`, `rtm_connect` and `rtm_read` to whichever client the app type allows.

Below that is the transcript of the ported bot started with a placeholder token: it fails inside `auth_test` with Slack's `invalid_auth` answer, which is the point where the old code failed with `SlackLoginError`, so the reviewer can see the code before that point runs. The session's record keeps every command the agent ran to get there.

Before merging, a reviewer checks the parts only they can do: whether the Slack app is classic or current, which decides the event loop; the scopes the bot needs for `chat:write` and for reading messages; and, for Socket Mode, generating the app-level token and enabling the feature in the app settings. The pull request lists those steps with the exact setting names.

## Run it on every rebuilt environment that fails on this import

This error does not come from a commit. A container image is rebuilt, a new server is provisioned, or a Python upgrade forces a fresh install, and the bot that has run for years stops at line 4. Add an automation to the Project with the prompt above and a `webhook` trigger, then have the deploy script post the failing output to the trigger's URL with `Authorization: Bearer` and the trigger's secret when the start command fails and its output contains `No module named 'slackclient'`. The posted text is placed after the saved prompt as the event.

Send an `Idempotency-Key` header to the trigger's URL set to the deploy's own id, so a retried deploy starts nothing new. An organisation that still has several small bots on the old library starts one run per repository with the same request from a script, and reviews each port as it arrives.

## Why run it on Rush?

The port touches a library with a token in its constructor and a network loop in its main function, which is the kind of code nobody wants to run on a laptop with the production token in the shell. A Rush sandbox has no token unless the request gives it one, so the agent proves the port up to Slack's auth check and no further, and the transcript shows that nothing was posted anywhere.

It also settles the pin-or-port question with evidence instead of opinion. The pinned install, the date of that line's last release, the deprecation warning the 2.x package prints and the method names of the maintained package are all read from installed code in the session, so the reviewer sees why the pull request chose the longer fix.

## Frequently asked questions

### Why does pip say the install worked when the import fails?

Because the project name and the import name differ. `pip install slackclient` has installed a package whose top-level module is `slack` since 2.0.0 in 2019; the old `slackclient` module only exists in the 1.x line. The agent shows both by installing each and listing what landed in `site-packages`.

### Can I pin slackclient below 2 and move on?

It installs and imports today. The 1.x line stopped at 1.3.2 in May 2019 and depends on an old websocket-client, so the pin buys time rather than a fix. The agent reports the pinned result and ports the code, which is also the only path that keeps receiving security fixes.

### Does slack_sdk still support the RTM loop my bot uses?

Through `slack_sdk.rtm_v2`, for classic Slack apps only; Slack stopped letting new apps use RTM. A current app gets its events through Socket Mode or an HTTP endpoint, which changes the loop and needs an app-level token. The agent reads the repository to decide which case applies and says so in the pull request.

### Will the agent run the bot against my workspace?

No. It runs the ported bot with a placeholder token, which Slack rejects at the auth check with `invalid_auth`, and stops there. Everything up to that point, the imports, the client construction and the request itself, is exercised. Posting a message needs a real token, which stays with you.

## More jobs like this: Fix a bug from an alert

- [Fix "ModuleNotFoundError: No module named 'smtpd'" on Python 3.12](https://getrush.ai/run/fix-no-module-named-smtpd/smtpd/)
- [Fix "ModuleNotFoundError: No module named 'telnetlib'" on Python 3.13](https://getrush.ai/run/fix-no-module-named-telnetlib/telnetlib/)
- [Fix "Node.js 20 actions are deprecated" Annotations in GitHub Actions Workflows](https://getrush.ai/run/fix-node-js-20-actions-are-deprecated/github-actions/)
- [Fix "Node Sass does not yet support your current environment" on a current Node release](https://getrush.ai/run/fix-node-sass-unsupported-environment/node-sass/)
- [Fix "ValueError: 'not' is not a valid parameter name" in a FastAPI App on Python 3.11 or Later](https://getrush.ai/run/fix-not-is-not-a-valid-parameter-name/pydantic/)
- [Fix "np.alltrue was removed in the NumPy 2.0 release"](https://getrush.ai/run/fix-np-alltrue-was-removed-in-the-numpy-2-release/numpy/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
