Python-slack-sdk: ImportError: No module named slackclient

Created on 18 May 2017  ยท  18Comments  ยท  Source: slackapi/python-slack-sdk

  • [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [x] I've read and agree to the Code of Conduct.
  • [x] I've searched for any related issues and avoided creating a duplicate issue.

Description

Reproducible in:

  • [x] This is reproducible in the sample project.
    python-slackclient version: Up-to-date
    Python Version:2.7
    OS Version: 10.12.4 (16E195)

Steps to reproduce:



    1. 2.
  1. 3.

Expected result:

Run slackclient

Actual result:

told me ImportError: No module named slackclient

Attachments:

from slackclient import SlackClient
from bs4 import BeautifulSoup
import urllib2
import requests
import re

I just import the required package but it told me not found slackclient
I tried install and uninstall and then re-install
but not working
Mac system version : 10.12.4 (16E195)

Most helpful comment

@NathanSepulveda
Oh, it seems you're using the old version of the package now. That is, for some reason you have v1 installed. In v1, the module was also named slackclient and featured a class named SlackClient. In v2, the module name changed to slack, (but the package is still named slackclient) and the client was split into WebClient and RtmClient.

Just to be clear as crystal, v2 of this package is meant to be installed as slackclient but used as slack. That is, you could do (kind of[1]):

$ pip3 install slackclient

And then this code would work:

import slack      # not slackclient!

The names are different depending on where you use it, but point to the same thing. Sorry about that confusion ๐Ÿ˜•. Even though you install a package named slackclient, you import a module named slack... in v2.

It looks like you had v2 installed, but were trying to import it with the wrong name. Somehow, you installed v1 of this package and are using that now.

How do I upgrade?

Take a peek at this solution I wrote for upgrading your package install to v2. After upgrading your slackclient package to v2, you'll be able to import slack and use the WebClient.


Notes

[1]: Only applies to fresh installs. If you try to pip3 install a package you have installed, pip3 will skip it, even if it's outdated.

All 18 comments

If you look in the folder where all of your packages are you can see the slackclient actually installed a folder called slackbot and not slackclient. If you do from slackbot.slackclient import SlackClient it should resolve the issue

@Celo44 That's a different library: https://github.com/lins05/slackbot

The issue here might be how the package is installed and which Python version it's being installed under. @Roron0a what did you run to install the slackclient package?

You should be able to run pip install slackclient

then your example app:

from slackclient import SlackClient
. . .

@Roach I don't know how I missed that!?! thank you!

So I've installed slackclient with the pip command listed above and python still can't find it... I'm super confused as to why. if I use the pip command again it says all the requirements are already resolved. Any ideas?

@GFBryson
the pip command you are using sounds like it is installing to a different interpreter than you are importing from.
try installing with python -m pip install slackclient or python3 -m pip install slackclient

All you are exactly right!! Thanks ๐Ÿ™๐Ÿผ

My issue was that I needed to migrate to version 2 of slackclient, as described in this issue: https://github.com/slackapi/python-slackclient/issues/178

I am having the same issue.
I am using a raspberry and with virtualenv 16.7.2.
I am getting this error "Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'slackclient'
"
But I apparently do have slackclient installed based on this :
"Requirement already satisfied: slackclient in /home/pi/testing/my_new_slack/lib/python3.6/site-packages (2.1.0)"

I've tried @cgoldberg 's recommendation but that has not solved the issue. I'd appreciate any advice!

@NathanSepulveda
๐Ÿ‘‹ I may be able to help! โ›‘
It seems like you're attempting to use the name slackclient in your import statement. While you install the package slackclient, the actual module name is slack! For example:

import slack

# or:

from slack import WebClient

Let me know if that does/doesn't work. ๐Ÿ˜Š

@clavin
Thanks for the suggestion! But I am indeed trying to use the module slackclient. This code runs of my Mac just fine:
```from slackclient import SlackClient
from playsound import playsound

slack_client = SlackClient()

user_list = slack_client.api_call('users.list')

if slack_client.rtm_connect():
print("connected")
while True:
for message in slack_client.rtm_read():
if 'text' in message:
print(message['text'])
if "new deal" in message['text']:
slack_client.api_call(
'chat.postMessage',
channel=message['channel'],
text="Good job guys!"
)
playsound('celebrate.mp3')
elif "New Demo Request" in message['text']:
slack_client.api_call(
'chat.postMessage',
channel=message['channel'],
text="Good job guys!"
)
playsound('celebrate.mp3')
```

@NathanSepulveda
Oh, it seems you're using the old version of the package now. That is, for some reason you have v1 installed. In v1, the module was also named slackclient and featured a class named SlackClient. In v2, the module name changed to slack, (but the package is still named slackclient) and the client was split into WebClient and RtmClient.

Just to be clear as crystal, v2 of this package is meant to be installed as slackclient but used as slack. That is, you could do (kind of[1]):

$ pip3 install slackclient

And then this code would work:

import slack      # not slackclient!

The names are different depending on where you use it, but point to the same thing. Sorry about that confusion ๐Ÿ˜•. Even though you install a package named slackclient, you import a module named slack... in v2.

It looks like you had v2 installed, but were trying to import it with the wrong name. Somehow, you installed v1 of this package and are using that now.

How do I upgrade?

Take a peek at this solution I wrote for upgrading your package install to v2. After upgrading your slackclient package to v2, you'll be able to import slack and use the WebClient.


Notes

[1]: Only applies to fresh installs. If you try to pip3 install a package you have installed, pip3 will skip it, even if it's outdated.

@clavin
Thanks for the help and thorough explanation!

Make following changes
from slack import WebClient
slack_client=WebClient(your_token)

I am facing import error for WebClient.. what to do?

I am facing import error for WebClient.. what to do?
@Akoparna24 What is your python version? I am able to import it in Python 3.7.3

@saurabh896 My python version is 3.8. So I have created a virtual environment of version 3.6 to run rasa.

@Akoparna24 Can you provide code snippet where you getting that error?

Make following changes
from slack import WebClient
slack_client=WebClient(your_token)

it works !! Thanks

Was this page helpful?
0 / 5 - 0 ratings