Python can't find installed module ('slackclient')

Question:

I am trying to build a slack bot for learning purpose but when I run the script get this error ModuleNotFoundError: No module named 'slackclient'

I tried install and uninstall and then re-install with python -m pip install slackclient

import os
import time
import re
from slackclient import SlackClient

# instantiate Slack client
slack_client = SlackClient(os.environ.get('SLACK_BOT_TOKEN'))

if __name__ == "__main__":
    if slack_client.rtm_connect(with_team_state=False):
        print("Starter Bot connected and running!")
        #Read bot's user ID by calling Web API method 'auth.test'
        starterbot_id = slack_client.api_call("auth.test")["user_id"]
        while True:
            command, channel = parse_bot_commands(slackclient.rtm_read())
            if command:
                handle_command(command, channel)
            time.sleep(RTM_READ_DELAY)
    else:
        print("Connection failed. Exception traceback printed above.")


(STARTE~1) C:UsersenestDesktopSlack Botstarterbot>python starterbot.py
Traceback (most recent call last):
  File "starterbot.py", line 4, in <module>
    from slackclient import SlackClient
ModuleNotFoundError: No module named 'slackclient'

(STARTE~1) C:UsersenestDesktopSlack Botstarterbot>pip install slackclient
Requirement already satisfied: slackclient in c:usersenestdesktopslackb~1starte~1libsite-packages (2.1.0)
Requirement already satisfied: aiohttp>3.5.2 in c:usersenestdesktopslackb~1starte~1libsite-packages (from slackclient) (3.5.4)
Requirement already satisfied: chardet<4.0,>=2.0 in c:usersenestdesktopslackb~1starte~1libsite-packages (from aiohttp>3.5.2->slackclient) (3.0.4)
Requirement already satisfied: async-timeout<4.0,>=3.0 in c:usersenestdesktopslackb~1starte~1libsite-packages (from aiohttp>3.5.2->slackclient) (3.0.1)
Requirement already satisfied: multidict<5.0,>=4.0 in c:usersenestdesktopslackb~1starte~1libsite-packages (from aiohttp>3.5.2->slackclient) (4.5.2)
Requirement already satisfied: yarl<2.0,>=1.0 in c:usersenestdesktopslackb~1starte~1libsite-packages (from aiohttp>3.5.2->slackclient) (1.3.0)
Requirement already satisfied: attrs>=17.3.0 in c:usersenestdesktopslackb~1starte~1libsite-packages (from aiohttp>3.5.2->slackclient) (19.1.0)
Requirement already satisfied: idna>=2.0 in c:usersenestdesktopslackb~1starte~1libsite-packages (from yarl<2.0,>=1.0->aiohttp>3.5.2->slackclient) (2.8)
Asked By: enestatli

||

Answers:

While the PyPI package is called slackclient, you import the module using the name slack:

import slack

Or, for example:

from slack import WebClient

Reference: https://github.com/slackapi/python-slackclient/wiki/Migrating-to-2.x

Answered By: arjitsrivastava13

I had this same error and found that the problem was my python settings in Visual Studio Code. I needed to change my python path from "/usr/bin/python" to "/usr/local/bin/python3" in the settings.json file. More details here.

Not sure if that was the editor you were using, but essentially whenever I pressed the little play button at the top right corner of the editor, to run my python file in the Visual Studio Code terminal, it was running the command python instead of python3 on the file.

Answered By: Brblmaur

you can fix: Download C++ new version https://visualstudio.microsoft.com/visual-cpp-build-tools/ https://visualstudio.microsoft.com/visual-cpp-build-tools/

Answered By: aemre

If your using python3 on your machine. You have to use pip3 to fix ModuleNotFoundError: No module named 'slack'. And it works for me.

pip3 install slack

After successful installation we can use

import slack

or,

from slack import WebClient