nltk successfully installed, but now I can't import it - nltk

I just installed nltk and now it's not working, and I need assistance figuring out what's wrong.
I followed the install guide here [https://pythonprogramming.net/tokenizing-words-sentences-nltk-tutorial/][1]
Installed via pip
sudo pip install nltk
Then I launched python and downloaded all components
# python3
>>> import nltk
>>> nltk.download()
This worked, and it downloaded all the components(I chose all). After which I figured I was good to go. However, then I went to write my first script and it errored out on the 1st line which imported nltk.
Now when I open the python interpreter I get
# python3
>>> import nltk
"2016-03-02 04:34:03,630","regex.py","ERROR","There is a problem with your SQL query: SELECT regex, regex_id FROM regex WHERE type = 'date'"
Traceback (most recent call last):
File "/home/nick/booze-dev/regex.py", line 10, in <module>
cursor.execute(SQL) # Execute SQL
NameError: name 'cursor' is not defined
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.4/dist-packages/nltk/__init__.py", line 128, in <module>
from nltk.chunk import *
File "/usr/local/lib/python3.4/dist-packages/nltk/chunk/__init__.py", line 157, in <module>
from nltk.chunk.api import ChunkParserI
File "/usr/local/lib/python3.4/dist-packages/nltk/chunk/api.py", line 15, in <module>
from nltk.chunk.util import ChunkScore
File "/usr/local/lib/python3.4/dist-packages/nltk/chunk/util.py", line 13, in <module>
from nltk.tag.mapping import map_tag
File "/usr/local/lib/python3.4/dist-packages/nltk/tag/__init__.py", line 63, in <module>
from nltk.tag.sequential import (SequentialBackoffTagger, ContextTagger,
File "/usr/local/lib/python3.4/dist-packages/nltk/tag/sequential.py", line 25, in <module>
from nltk.classify import NaiveBayesClassifier
File "/usr/local/lib/python3.4/dist-packages/nltk/classify/__init__.py", line 98, in <module>
from nltk.classify.textcat import TextCat
File "/usr/local/lib/python3.4/dist-packages/nltk/classify/textcat.py", line 47, in <module>
import regex as re
File "/home/nick/booze-dev/regex.py", line 14, in <module>
sys.exit("Aborting script execution")
NameError: name 'sys' is not defined
I didn't get that error the 1st time I ran the import and executed nltk.download(), so I'm not understanding why I'm getting it now.
I've tried executing python as root and my normal user, and get the same error.
If I check my sys.path
>>> import sys
>>> sys.path
['', '/usr/lib/python3.4', '/usr/lib/python3.4/plat-x86_64-linux-gnu', '/usr/lib/python3.4/lib-dynload', '/usr/local/lib/python3.4/dist-packages', '/usr/lib/python3/dist-packages']
I can find nltk under /usr/local/lib/python3.4/dist-packages:
# ls /usr/local/lib/python3.4/dist-packages | grep nltk
nltk
nltk-3.1.egg-info
So it should be available. So why am I getting an error when importing now?

Related

Airflow gives error ImportError: No module named MySQLdb upon changing its config file for celery

I have installed airflow with celery in my ec2 linux instance and airflow is working like a charm. Now when I made changes in its config file to use celery with airflow it is throwing the following error.
[2020-04-03 07:24:57,234] {settings.py:253} INFO - settings.configure_orm(): Using pool settings. pool_size=5, max_overflow=10, pool_recycle=1800, pid=4851
Traceback (most recent call last):
File "/usr/local/bin/airflow", line 25, in <module>
from airflow.configuration import conf
File "/usr/local/lib/python2.7/site-packages/airflow/__init__.py", line 47, in <module>
settings.initialize()
File "/usr/local/lib/python2.7/site-packages/airflow/settings.py", line 377, in initialize
configure_orm()
File "/usr/local/lib/python2.7/site-packages/airflow/settings.py", line 266, in configure_orm
engine = create_engine(SQL_ALCHEMY_CONN, **engine_args)
File "/usr/local/lib64/python2.7/site-packages/sqlalchemy/engine/__init__.py", line 479, in create_engine
return strategy.create(*args, **kwargs)
File "/usr/local/lib64/python2.7/site-packages/sqlalchemy/engine/strategies.py", line 87, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "/usr/local/lib64/python2.7/site-packages/sqlalchemy/dialects/mysql/mysqldb.py", line 118, in dbapi
return __import__("MySQLdb")
ImportError: No module named MySQLdb
pip install MySQL-python
Should fix this

How to fix 'AttributeError: type object 'pyfmi.fmi.ModelBase' has no attribute '__reduce_cython__''

I am importing pyfmi and get this error message. I am using Spyder (Python 3.6) on windows.
I also downloaded the latest version of Cython 0.29.13
import pyfmi
Traceback (most recent call last):
File "<ipython-input-11-df481fa81f2d>", line 1, in <module>
import pyfmi
File "C:\ProgramData\Anaconda3\lib\site-packages\pyfmi\__init__.py", line 24, in <module>
from .fmi import FMUModel, load_fmu, FMUModelME1, FMUModelME2
File "src\pyfmi\fmi.pyx", line 165, in init pyfmi.fmi
AttributeError: type object 'pyfmi.fmi.ModelBase' has no attribute '__reduce_cython__'

OSError: libcudart.so.9.2: cannot open shared object file: No such file or directory

trying to run a script, when i get
(infacepytorch) ryan#ryan-7570:/media/ryan/shakira/InsightFace_Pytorch$ python face_verify.py
Traceback (most recent call last):
File "face_verify.py", line 9, in <module>
from Learner import face_learner
File "/media/ryan/shakira/InsightFace_Pytorch/Learner.py", line 1, in <module>
from data.data_pipe import de_preprocess, get_train_loader, get_val_data
File "/media/ryan/shakira/InsightFace_Pytorch/data/data_pipe.py", line 12, in <module>
import mxnet as mx
File "/home/ryan/virtualenvs/infacepytorch/lib/python3.5/site-packages/mxnet/__init__.py", line 24, in <module>
from .context import Context, current_context, cpu, gpu, cpu_pinned
File "/home/ryan/virtualenvs/infacepytorch/lib/python3.5/site-packages/mxnet/context.py", line 24, in <module>
from .base import classproperty, with_metaclass, _MXClassPropertyMetaClass
File "/home/ryan/virtualenvs/infacepytorch/lib/python3.5/site-packages/mxnet/base.py", line 213, in <module>
_LIB = _load_lib()
File "/home/ryan/virtualenvs/infacepytorch/lib/python3.5/site-packages/mxnet/base.py", line 204, in _load_lib
lib = ctypes.CDLL(lib_path[0], ctypes.RTLD_LOCAL)
File "/usr/lib/python3.5/ctypes/__init__.py", line 347, in __init__
self._handle = _dlopen(self._name, mode)
OSError: libcudart.so.9.2: cannot open shared object file: No such file or directory
I have tried
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64 && sudo ldconfig
but i still get the same error,
Any suggestions would be really helpfull, Thanks in advance.
As pointed out by talonmies you're running a version of MXNet that depends on Cuda-9.2. It would be preferable to install Cuda-9.2 and update your library path to point to 9.2.
You can also also install MXNet for 9.0 using the pip package mxnet-cu90 if you were unable to update your Cuda dependencies.

Import globally installed module

I am trying to execute my python script which imports globally installed modules through pip. (Module like nltk)
Below is my code.
interpreter.execfile("/home/roy/eclipse-workspace/geospatial-analysis/src/main/resources/wordnet_util.py");
PyObject someFunc = interpreter.get("get_similarity");
PyObject result = someFunc.__call__(new PyString("Apple pie."), new PyString("Banana pie."));
Double realResult = (Double) result.__tojava__(Double.class);
I have added the path for python modules like,
import sys
sys.path.append("/usr/local/lib/python2.7/dist-packages")
But I get the following error,
*sys-package-mgr*: can't create package cache dir, '/usr/local/lib/python2.7/dist-packages/cachedir/packages'
Exception in thread "main" Traceback (most recent call last):
File "/home/roy/eclipse-workspace/geospatial-analysis/src/main/resources/wordnet_util.py", line 6, in <module>
from nltk import word_tokenize, pos_tag
File "/usr/local/lib/python2.7/dist-packages/nltk/__init__.py", line 18, in <module>
from __future__ import print_function, absolute_import
ImportError: No module named __future__
Update:
I added sys.path.append("/usr/lib/python2.7") to the python file. It solved the above error. Now it can't find select module.
ImportError: No module named signal

No module named constants error

I have a project in progress. In this project I have to change some reports that they implement by XML code.
When I run my project with "python manage.py runserver"it runs truthfully and I can change my XML code and see the HTML files on chrome but when I want to see the PDF file of reports I get an error that says:
>"IndexError, your list is out of range"
so I start to debug it, in this process debugger said
"from django.db.models.constants import LOOKUP_SEP No module named constants".
this is whole trace back:
>Unhandled exception in thread started by <_pydev_bundle.pydev_monkey._NewThreadStartupWithTrace instance at 0x7f45ea1f3b48>
Traceback (most recent call last):
File "/home/rajabi/pycharm-community-2017.1.4/helpers/pydev/_pydev_bundle/pydev_monkey.py", line 589, in __call__
return self.original_func(*self.args, **self.kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 91, in inner_run
self.validate(display_num_errors=True)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/validation.py", line 30, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 158, in get_app_errors
self._populate()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 67, in _populate
self.load_app(app_name)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 88, in load_app
models = import_module('.models', app_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/rajabi/Desktop/tina/clone-2017-07-05/rtis/src/saed/activities/models.py", line 7, in <module>
from saed.activities.base import models
File "/home/rajabi/Desktop/tina/clone-2017-07-05/rtis/src/saed/activities/base/models.py", line 16, in <module>
from model_utils.managers import InheritanceManager
File "/usr/local/lib/python2.7/dist-packages/model_utils/managers.py", line 13, in <module>
from django.db.models.constants import LOOKUP_SEP
ImportError: No module named constants
what should I do?
django==1.4
python==2.7.12
tastypie == 0.9.16
I can't change my django and python version.
This part of the traceback is showing you that the error is coming from django-model-utils.
File "/usr/local/lib/python2.7/dist-packages/model_utils/managers.py", line 13, in <module>
from django.db.models.constants import LOOKUP_SEP
The release notes say that support for Django 1.4 was dropped in version 3.0.
You could try installing an early version of django-model-utils, but really you should upgrade Django. Django 1.4 is years out of date and insecure.