Run slackclient
told me ImportError: No module named slackclient
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)
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 "
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.
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.
[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
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
slackclientand featured a class namedSlackClient. In v2, the module name changed toslack, (but the package is still namedslackclient) and the client was split intoWebClientandRtmClient.Just to be clear as crystal, v2 of this package is meant to be installed as
slackclientbut used asslack. That is, you could do (kind of[1]):And then this code would work:
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 namedslack... 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
slackclientpackage to v2, you'll be able toimport slackand use theWebClient.Notes
[1]: Only applies to fresh installs. If you try to
pip3 installa package you have installed,pip3will skip it, even if it's outdated.