slackapi/python-slack-sdk

ModuleNotFoundError: no module named 'slack'

Closed this issue · 14 comments

I would like to be able to import slack into python vscode. Im getting a ModuleNotFoundError after downloading slackclient from the terminal.

Reproducible in:

SlackClient 2.9.4
slack_sdk     3.27.0
python --version 3.12
MacOS

The Slack SDK version

slack_sdk 3.27.0

Python runtime version

python --version 3.12

macOS

Steps to reproduce:

import os
import slack
from pathlib import Path

Expected result:

import slack to function correctly

Actual result:

Screenshot 2024-02-20 at 6 29 10 PM Screenshot 2024-02-20 at 6 31 18 PM

Hey @Usefultoaster 👋 Does this also happen if you try the following?

import slack_sdk

@zimeg Yes it does, same error.

🤔 Did you happen to install slack_sdk to or activate a virtual environment? I also think the slackclient package can be removed as part of the migration to slack_sdk v3, but am not sure if that fix things.

There's also a chance that restarting the editor might refresh things. Sometimes the classic off-and-on can work wonders!

Hmmm, I had both slack_sdk and slackclient installed. I've tried using the import with both installed, just slackclient installed, and just slack_sdk installed. None of those worked, I have the most recent version of all of these. I've restarted my mac and just vscode multiple times also.

How are you installing the packages? There may be something unusual happening between your package environment and editor.

🤔 Interesting, is both slackclient and slack_sdk needed for what you're doing? I believe slack_sdk is the preferred later version. I'm not sure if restarting the editor after only installing that one might work.

This article might be useful for connecting any virtual environment to the editor too! Please let me know if any of that seems to help

I've tried it multiple times with just slack_sdk installed. I made a .env file but cant really use it just yet since import slack isnt working.

You might have to activate the virtual environment then install slack_sdk for things to sync up properly. The following commands might change something:

$ python3 -m venv .venv
$ source .venv/bin/activate
$ pip install slack_sdk

I'm also curious if you can run your scripts alright, even with the error in the editor, or if this package installation isn't found from the command line either?

Activating the virtual environment changed the download of slack a little bit, it actually downloaded each time. After I did that it still doesn't work is vscode. It seems like I can't run the script either.

Maybe there's a mismatch of the interpreter being used? Could you check that the virtual environment is selected for your session? It should be something like ./.venv/bin/python.

If that looks good and you've activated the virtual environment, I'm also curious which python is being used. In my testing I get something like this:

(.venv) $ which python
/Users/me/path/to/project/.venv/bin/python

The slack_sdk package is also appearing in my pip list and .venv/lib/python3.11/site-packages directory too. But please let me know if any of this seems off since I'm having trouble reproducing the ModuleNotFoundError myself.

👋 It looks like this issue has been open for 30 days with no activity. We'll mark this as stale for now, and wait 10 days for an update or for further comment before closing this issue out. If you think this issue needs to be prioritized, please comment to get the thread going again! Maintainers also review issues marked as stale on a regular basis and comment or adjust status if the issue needs to be reprioritized.

As this issue has been inactive for more than one month, we will be closing it. Thank you to all the participants! If you would like to raise a related issue, please create a new issue which includes your specific details and references this issue number.