NLTK library not working with python - python

I tried to import nltk library in my python code(Mac OS). and i get this error message. is there a specific nltk software i should install? or what the right command to write in the terminal?
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import nltk
File "/Library/Python/2.7/site-packages/nltk/__init__.py", line 128, in <module>
from nltk.chunk import *
File "/Library/Python/2.7/site-packages/nltk/chunk/__init__.py", line 157, in <module>
from nltk.chunk.api import ChunkParserI
File "/Library/Python/2.7/site-packages/nltk/chunk/api.py", line 15, in <module>
from nltk.chunk.util import ChunkScore
File "/Library/Python/2.7/site-packages/nltk/chunk/util.py", line 13, in <module>
from nltk.tag.mapping import map_tag
File "/Library/Python/2.7/site-packages/nltk/tag/__init__.py", line 63, in <module>
from nltk.tag.sequential import (SequentialBackoffTagger, ContextTagger,
File "/Library/Python/2.7/site-packages/nltk/tag/sequential.py", line 25, in <module>
from nltk.classify import NaiveBayesClassifier
File "/Library/Python/2.7/site-packages/nltk/classify/__init__.py", line 98, in <module>
from nltk.classify.textcat import TextCat
File "/Library/Python/2.7/site-packages/nltk/classify/textcat.py", line 47, in <module>
import regex as re
File "/Library/Python/2.7/site-packages/regex.py", line 672, in <module>
_pattern_type = type(_compile("", 0, {}))
File "/Library/Python/2.7/site-packages/regex.py", line 425, in _compile
pattern_locale = _getlocale()[1]
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 562, in getlocale
return _parse_localename(localename)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 475, in _parse_localename
raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8

Related

In pydroid3, I have installed pywhatkit5.4 using pip menu. But, import pywhatkit in program fails

Traceback (most recent call last):
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module>
start(fakepyfile,mainpyfile)
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start
exec(open(mainpyfile).read(), __main__.__dict__)
File "<string>", line 2, in <module>
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/pywhatkit/__init__.py", line 16, in <module>
from pywhatkit.whats import (
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/pywhatkit/whats.py", line 7, in <module>
import pyautogui as pg
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/pyautogui/__init__.py", line 249, in <module>
import mouseinfo
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/mouseinfo/__init__.py", line 223, in <module>
_display = Display(os.environ['DISPLAY'])
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/os.py", line 679, in __getitem__ raise KeyError(key) from None
KeyError: 'DISPLAY'
[Program finished]
import pywhatkit
pywhatkit.sendwhatmsg ("+9195352xxxx5", "Hello ", 14, 10)
pywhatkit not getting imported in this 2 line program. Above is the error message.

WinError 123 The filename, directory name, or volume label syntax is incorrect --> while importing transformers

I tried below code:
import transformers
and got below error:
import transformers
File "C:\Users\user1\AppData\Roaming\Python\Python37\site-packages\transformers\__init__.py", line 22, in <module>
from .integrations import ( # isort:skip
File "C:\Users\user1\AppData\Roaming\Python\Python37\site-packages\transformers\integrations.py", line 58, in <module>
from .file_utils import is_torch_tpu_available
File "C:\Users\user1\AppData\Roaming\Python\Python37\site-packages\transformers\file_utils.py", line 156, in <module>
import sklearn.metrics # noqa: F401
File "C:\Users\user1\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\metrics\__init__.py", line 7, in <module>
from .ranking import auc
File "C:\Users\user1\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\metrics\ranking.py", line 35, in <module>
from ..preprocessing import label_binarize
File "C:\Users\user1\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\preprocessing\__init__.py", line 6, in <module>
from ._function_transformer import FunctionTransformer
File "C:\Users\user1\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\preprocessing\_function_transformer.py", line 5, in <module>
from ..utils.testing import assert_allclose_dense_sparse
File "C:\Users\user1\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\utils\testing.py", line 718, in <module>
import pytest
File "C:\Users\user1\AppData\Local\Continuum\anaconda3\lib\site-packages\pytest.py", line 6, in <module>
from _pytest.assertion import register_assert_rewrite
File "C:\Users\user1\AppData\Local\Continuum\anaconda3\lib\site-packages\_pytest\assertion\__init__.py", line 7, in <module>
from _pytest.assertion import rewrite
File "C:\Users\user1\AppData\Local\Continuum\anaconda3\lib\site-packages\_pytest\assertion\rewrite.py", line 26, in <module>
from _pytest.assertion import util
File "C:\Users\user1\AppData\Local\Continuum\anaconda3\lib\site-packages\_pytest\assertion\util.py", line 8, in <module>
import _pytest._code
File "C:\Users\user1\AppData\Local\Continuum\anaconda3\lib\site-packages\_pytest\_code\__init__.py", line 2, in <module>
from .code import Code # noqa
File "C:\Users\user1\AppData\Local\Continuum\anaconda3\lib\site-packages\_pytest\_code\code.py", line 23, in <module>
import pluggy
File "C:\Users\user1\AppData\Local\Continuum\anaconda3\lib\site-packages\pluggy\__init__.py", line 16, in <module>
from .manager import PluginManager, PluginValidationError
File "C:\Users\user1\AppData\Local\Continuum\anaconda3\lib\site-packages\pluggy\manager.py", line 11, in <module>
import importlib_metadata
File "C:\Users\user1\AppData\Local\Continuum\anaconda3\lib\site-packages\importlib_metadata\__init__.py", line 547, in <module>
__version__ = version(__name__)
File "C:\Users\user1\AppData\Local\Continuum\anaconda3\lib\site-packages\importlib_metadata\__init__.py", line 509, in version
return distribution(distribution_name).version
File "C:\Users\user1\AppData\Local\Continuum\anaconda3\lib\site-packages\importlib_metadata\__init__.py", line 482, in distribution
return Distribution.from_name(distribution_name)
File "C:\Users\user1\AppData\Local\Continuum\anaconda3\lib\site-packages\importlib_metadata\__init__.py", line 183, in from_name
dist = next(dists, None)
File "C:\Users\user1\AppData\Local\Continuum\anaconda3\lib\site-packages\importlib_metadata\__init__.py", line 425, in <genexpr>
for path in map(cls._switch_path, paths)
File "C:\Users\user1\AppData\Local\Continuum\anaconda3\lib\site-packages\importlib_metadata\__init__.py", line 449, in _search_path
if not root.is_dir():
File "C:\Users\user1\AppData\Local\Continuum\anaconda3\lib\pathlib.py", line 1358, in is_dir
return S_ISDIR(self.stat().st_mode)
File "C:\Users\user1\AppData\Local\Continuum\anaconda3\lib\pathlib.py", line 1168, in stat
return self._accessor.stat(self)
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'C:\\Users\\user1\\Spark\\python\\lib\\py4j-0.10.8.1-src.zip:C:\\Users\\user1\\Spark\\python'
So, here is the error:
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'C:\Users\user1\Spark\python\lib\py4j-0.10.8.1-src.zip:C:\Users\user1\Spark\python'
This is happening only for transformers package and rest like pandas or numpy or torch give no issues.
I see quite a few links giving solutions to this error, but more appear related to syntax of the code (like using double quotes or having an additional backlash).
What am I missing? Thanks in advance for any help.
I am still not sure of the reason for the error, but I could overcome the same by creating an environment and then installing transformers in it.
Hope this will help someone stuck with same error

ImportError: cannot import name 'request'

I am a windows user. I used the command pip install requests to have requests installed, and I also typedpip install urllib3 to have urllib3 installed. However, I am not able to run this code: from requests import request. I got a error like this:
Traceback (most recent call last):
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\packages\__init__.py", line 27, in <module>
from . import urllib3
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\packages\urllib3\__init__.py", line 8, in <module>
from .connectionpool import (
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\packages\urllib3\connectionpool.py", line 11, in <module>
from .exceptions import (
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\packages\urllib3\exceptions.py", line 2, in <module>
from .packages.six.moves.http_client import (
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\packages\urllib3\packages\six.py", line 203, in load_module
mod = mod._resolve()
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\packages\urllib3\packages\six.py", line 115, in _resolve
return _import_module(self.mod)
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\packages\urllib3\packages\six.py", line 82, in _import_module
__import__(name)
File "D:\Python\lib\http\client.py", line 71, in <module>
import email.parser
File "F:\eclipse\workspace\Overseascredit\email.py", line 1, in <module>
from requests import request
ImportError: cannot import name 'request'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "F:\eclipse\workspace\Overseascredit\email.py", line 1, in <module>
from requests import request
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\__init__.py", line 60, in <module>
from .packages.urllib3.exceptions import DependencyWarning
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\packages\__init__.py", line 29, in <module>
import urllib3
File "D:\Python\lib\site-packages\urllib3\__init__.py", line 8, in <module>
from .connectionpool import (
File "D:\Python\lib\site-packages\urllib3\connectionpool.py", line 11, in <module>
from .exceptions import (
File "D:\Python\lib\site-packages\urllib3\exceptions.py", line 2, in <module>
from .packages.six.moves.http_client import (
File "D:\Python\lib\site-packages\urllib3\packages\six.py", line 203, in load_module
mod = mod._resolve()
File "D:\Python\lib\site-packages\urllib3\packages\six.py", line 115, in _resolve
return _import_module(self.mod)
File "D:\Python\lib\site-packages\urllib3\packages\six.py", line 82, in _import_module
__import__(name)
File "D:\Python\lib\http\client.py", line 71, in <module>
import email.parser
File "F:\eclipse\workspace\Overseascredit\email.py", line 1, in <module>
from requests import request
ImportError: cannot import name 'request'
I saw a lot of answers saying that there is another file with duplicate name that occur this error, however, I searched through the fold, I did found one. I even reinstalled my python, but I still got this error. Please help me.
Try using
from requests import Request
instead of
from requests import request

Cannot import Random in Python chatbot I am creating

I want to create a chatbot using the telegram api in Python, but I get an error.
Below is my code:
import telepot, time
import urllib3
def handle(msg):
chat_id = msg['chat']['id']
command = msg['text']
print 'Got command: %s' % command
if command == '/hello':
bot.sendMessage(chat_id, "Hello, how are you?")
bot = telepot.Bot('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
bot.notifyOnMessage(handle)
while 1:
time.sleep(10)
The error I am getting is:
Traceback (most recent call last):
File "C:\Users\KUNTALS\workspace\ChatBot\tel_bot4.py", line 1, in <module>
import telepot, time
File "C:\Python27\lib\site-packages\telepot\__init__.py", line 259, in <module>
from . import api
File "C:\Python27\lib\site-packages\telepot\api.py", line 1, in <module>
import urllib3
File "C:\Python27\lib\site-packages\urllib3\__init__.py", line 8, in <module>
from .connectionpool import (
File "C:\Python27\lib\site-packages\urllib3\connectionpool.py", line 11, in <module>
from .exceptions import (
File "C:\Python27\lib\site-packages\urllib3\exceptions.py", line 2, in <module>
from .packages.six.moves.http_client import (
File "C:\Python27\lib\site-packages\urllib3\packages\six.py", line 203, in load_module
mod = mod._resolve()
File "C:\Python27\lib\site-packages\urllib3\packages\six.py", line 115, in _resolve
return _import_module(self.mod)
File "C:\Python27\lib\site-packages\urllib3\packages\six.py", line 82, in _import_module
__import__(name)
File "C:\Python27\lib\httplib.py", line 80, in <module>
import mimetools
File "C:\Python27\lib\mimetools.py", line 6, in <module>
import tempfile
File "C:\Python27\lib\tempfile.py", line 35, in <module>
from random import Random as _Random
ImportError: cannot import name Random

Pass the values from multiple select list in html form using Flask

Try to run an app on local machine through virtual environment. But run into this issues related to libssl. Have libssl.1.0.0.dylib in the reference folder so I don't know why it cannot find the method. Really appreciate anyone can give me a direction.
Traceback (most recent call last):
File "app.py", line 4, in <module>
from traffic_analytics import traffic_analytics
File "/Users/zhehaozhou/Documents/Development/giq-analytics/dashboard-x/webapp/traffic_analytics.py", line 12, in <module>
from traffic import download_ga_data as ga_downloader
File "/Users/zhehaozhou/Documents/Development/giq-analytics/dashboard-x/webapp/traffic/download_ga_data.py", line 13, in <module>
from ga import GoogleAnalytics
File "/Users/zhehaozhou/Documents/Development/giq-analytics/dashboard-x/webapp/traffic/ga.py", line 8, in <module>
from apiclient import errors
File "/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/apiclient/__init__.py", line 19, in <module>
from googleapiclient import discovery
File "/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/googleapiclient/discovery.py", line 66, in <module>
from oauth2client.client import GoogleCredentials
File "/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/oauth2client/client.py", line 46, in <module>
from oauth2client import crypt
File "/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/oauth2client/crypt.py", line 40, in <module>
from OpenSSL import crypto
File "/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import rand, crypto, SSL
File "/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/OpenSSL/rand.py", line 11, in <module>
from OpenSSL._util import (
File "/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/OpenSSL/_util.py", line 7, in <module>
binding = Binding()
File "/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 114, in __init__
self._ensure_ffi_initialized()
File "/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 126, in _ensure_ffi_initialized
cls._modules,
File "/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/cryptography/hazmat/bindings/utils.py", line 31, in load_library_for_binding
lib = ffi.verifier.load_library()
File "/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/cffi/verifier.py", line 97, in load_library
return self._load_library()
File "/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/cffi/verifier.py", line 207, in _load_library
return self._vengine.load_library()
File "/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/cffi/vengine_cpy.py", line 153, in load_library
raise ffiplatform.VerificationError(error)
cffi.ffiplatform.VerificationError: importing '/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/cryptography/_Cryptography_cffi_f3e4673fx399b1113.so': dlopen(/Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/cryptography/_Cryptography_cffi_f3e4673fx399b1113.so, 2): Symbol not found: _SSLv2_client_method
Referenced from: /Users/zhehaozhou/anaconda/envs/virtualZhehao2/lib/python2.7/site-packages/cryptography/_Cryptography_cffi_f3e4673fx399b1113.so
Expected in: /usr/lib/libssl.1.0.0.dylib

Categories