'ModuleNotFoundError: No module named nltk.metrics' on 'import nltk' - python

I am working on Ubuntu and installed NLTK via apt-get for Python 3.6.
Here's my problem:
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/wizard/.local/lib/python3.6/site-packages/nltk/__init__.py", line 128, in <module>
from nltk.collocations import *
File "/wizard/.local/lib/python3.6/site-packages/nltk/collocations.py", line 39, in <module>
from nltk.metrics import (
ModuleNotFoundError: No module named 'nltk.metrics'
I am a beginner on Ubuntu so I don't know how to solve this. I assume that the metrics module didn't get installed with the rest?

Python librairies shouldn't be installed with apt-get but with pip.
In your case, you should install it with pip install nltk.
If you are new to Python and does not know about the package managing module Pip, check this website.
I advice you to use virtual environments aswell when working with Python, check info here.

Related

Python cannot find module, pip list does

So, this was my first time making a python package. I tried and tested and got it to work. This meaning that pip install . didn't complain and that
$sudo python3
>>>from LEDController import prettyLight
>>>prettyLight().light('whatsapp',100)
provided expected output and actions in my LED matrix.
Also pip list includes LEDControllerm but as soon as I start python3 anywhere but in the LEDController package directory, the module is not being found.
Running pip install /path/to/LEDController/ is still successfull, as is pip3 install /path/to/LEDController/.
Yet I get
$sudo python3
>>> import LEDController
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'LEDController'
>>> from LEDController import prettyLight
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'LEDController'
What am I missing?
As #sinoroc said, installing only using pip is not the safest option. Instead using python3 -m pip install /path/to/module fixed the issue perfectly.
I'll put his link here so future viewers can read up on why this is.

ImportError: No module named 'pip._vendor.requests' for python3

Have installed pip3 via sudo apt-get. But while trying to check the pip3 --version, its throwing
ImportError: No module named 'pip._vendor.requests'
How do i fix this?
server -- Linux Debian 4.9.65-3,
Python version -- Python 3.5.3
p.s. have tried uninstalling and reinstalling pip3 but no luck.
Full stack trace:-
Traceback (most recent call last): File "/usr/bin/pip3", line 9, in
from pip import main File "/usr/lib/python3/dist-packages/pip/init.py", line 21, in
from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning ImportError: No module named 'pip._vendor.requests'

pycrypto : No module named strxor

I got this error :
Traceback (most recent call last):
File "test.py", line 8, in <module>
from Crypto.Cipher import PKCS1_OAEP
File "C:\Users\Mokhles\Downloads\google-api-python-client-1.5.3\Crypto \Cipher\PKCS1_OAEP.py", line 57, in <module>
import Crypto.Signature.PKCS1_PSS
File "C:\Users\Mokhles\Downloads\google-api-python-client-1.5.3\Crypto \Signature\PKCS1_PSS.py", line 74, in <module>
from Crypto.Util.strxor import strxor
ImportError: No module named strxor
any idea how to solve it?
ENV:
-windows 10
-python 2.7
It looks like you're simply copied pyCrypto into your project. PyCrypto is library which depends on some native library/code (like libtomcrypt). You have to install it properly. You can do this for example through pip:
pip2 install pycrypto
or
pip3 install pycrypto
depending on which Python version you want to make it available.
try conda install pydotplus (may need to install tqdm first)

Anaconda not able to import the packages like numpy, scipy, theano etc

Without installing Anaconda, everything works fine.
That is, I am able to import the above mentioned packages. But after installing Anaconda, I am not able to import the same packages. Here is the error which I get: -
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/numpy/__init__.py", line 199, in <module>
from . import random
File "/usr/local/lib/python2.7/dist-packages/numpy/random/__init__.py", line 99, in <module>
from .mtrand import *
ImportError: /usr/local/lib/python2.7/dist-packages/numpy/random /mtrand.so: undefined symbol: PyFPE_jbuf
Once you install the Anaconda distribution it appends the .bashrc paths with the location of the anaconda/bin.
This means that any python packages installed in the /usr/local/ may not be importable.
I second the suggestion above and recommend using virtual environments to do your work. The Anaconda Python distribution comes with conda package management. This may make your life easier.
You can create a new environments and install packages not provided by the distribution using conda build(http://conda.pydata.org/docs/build_tutorials.html)
Also look at pip and python wheel.

I'm having troubles getting pybrain working through anaconda

Here is my problem:
After I managed to install anaconda (having python 3.4), I apparently managed to install pybrain too. But when i use 'import pybrain' from anaconda or from the terminal too I get this error:
>>> import pybrain
Traceback (most recent call last):
File "<ipython-input-2-0fb7233d2a8c>", line 1, in <module>
import pybrain
File "//anaconda/lib/python3.4/site-packages/PyBrain-0.3-py3.4.egg/pybrain/__init__.py", line 1, in <module>
from structure.__init__ import *
ImportError: No module named 'structure'
Simply running sudo pip3 install git+https://github.com/pybrain/pybrain.git worked for me after having the same issue.
The version up on PyPi isn't Python 3 compatible.
Installing the latest commit directly using pip3 should take care of your old package (from PyPi) as well.

Categories

Resources