No module named 'nltk' - python

I successfully installed nltk and works fine. I have to run a file where nltk was imported and tensorflow too ,hence, i have to activate tensorflow.
When I activate tensorflow the .py file i want to run gives an error. I have read some solution but they didn't help.
HP-250-G5-Notebook-PC:~$ python
Python 3.6.3 |Anaconda custom (64-bit)| (default, Oct 13 2017, 12:02:49)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
>>>
this works fine but this does not
(tensorflow)HP-250-G5-Notebook-PC:~/AIG2018/Chatbot$ python
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
What is that I am doing worng?
ImportError: No module named 'nltk'

You're using two different versions of python, and you probably installed nltk in your root environment, but not your virtual environment. When you "activate" the environment called tensorflow, you are using a different virtual environment, in which you haven't installed nltk. Try activating tensorflow, then using pip install nltk, then starting python. Because you seem to be using anaconda, this would probably look like this:
# Do these first 2 steps in your terminal:
source activate tensorflow
# you're now in the virtual environment called tensorflow
pip install nltk
# you now have nltk in that virtual environment
# Now, you can start python
python
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
And you shouldn't have that error

If you look closely at your messages you will see that the successful import of nltk is on Python 3.6.3 and the failed import is on Python 3.5.2.
This indicates that you have two Python installations of different versions, and nltk is installed in one but not in the other.

Related

Can't install Python 2 `gtop` module in virtual environment

I'm trying to run the benchmarks game repo bencher script which was written in python 2 and requires the gtop module, NOT the pygtop module. After searching everywhere and even following their README.md I could not figure out how to get this in my python 2.7.18 virtual environment (created and maintained using pyenv).
I decided to have a look at my system version of python 2.7.18 as I followed the guide from this SO reply and the packages downloaded/installed successfully. My system version of python can import the module just fine:
Python 2.7.18 (default, Mar 8 2021, 13:02:45)
[GCC 9.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gtop
>>> gtop.__file__
'/usr/lib/python2.7/dist-packages/gtk-2.0/gtop.so'
So apparently it comes as a .so which I've researched is like a DLL library for Ubuntu (correct me if I'm wrong)?
Is there a way for me to just copy this into my virtual environment of the same python version?
Thank you to #SamBob for suggesting the SO reply that led to the answer.
What I've been mistakenly doing is copying the gtk-2.0 directory into my virtualenvs site-packages such that:
$HOME/.pyenv/versions/<venv>/lib/python2.7/site-packages/gtk-2.0/gtop.so
What I've done is instead copy just the gtop.so library into the virtualenvs site-packages, and it seemed to recognise it no problem, such that
$HOME/.pyenv/versions/<venv>/lib/python2.7/site-packages/gtop.so
Here is my output now:
Python 2.7.18 (default, Oct 18 2021, 23:18:58)
[GCC 9.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gtop
>>> gtop.__file__
'/home/muffin/.pyenv/versions/project-2.7.18/lib/python2.7/site-packages/gtop.so'
>>>

import opencv with anaconda using python package

I'm currently working on a project with anaconda. I was able to install opencv-python with the regular pip3 install (not anacondas version). When I import cv2, its successful.
Python 3.6.9 (default, Oct 8 2020, 12:12:24)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>>
If I copy that package into my anaconda path, and run python with anaconda, import cv2 I get the following error:
Python 3.7.3 (default, Mar 27 2019, 22:11:17)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'
Is there a way to get around this without using the Anacondas pip install? I don't have internet on the machine I'm working on. I've done this method with other packages and it has worked fine, not with opencv.

Why opencv3 requires libavcodec56 although opencv2 requires libavcodec57

I have installed opencv using apt-get. I got opencv2 with the following version and it works fine:
rover#rover_pi:/usr/lib/arm-linux-gnueabihf $ python2.7
Python 2.7.13 (default, Nov 24 2017, 17:33:09)
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'2.4.9.1'
Then I wanted to install opencv on a conda environment using pip. I got the following version
(olfatf)rover#rover_pi:/usr/lib/arm-linux-gnueabihf $ pip list | grep opencv
opencv-python 3.4.0.14
However, I get the following error when I import the module:
(olfatf)rover#rover_pi:/usr/lib/arm-linux-gnueabihf $ python
Python 3.4.3 |Continuum Analytics, Inc.| (default, Aug 21 2015, 00:53:08)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/pi/.conda/envs/olfatf/lib/python3.4/site-packages/cv2/__init__.py", line 3, in <module>
from .cv2 import *
ImportError: libavformat.so.56: cannot open shared object file: No such file or directory
I checked the install libavcodec library and I get the version 57.
(olfatf)rover#rover_pi:/usr/lib/arm-linux-gnueabihf $ ls | grep libavformat
libavformat.a
libavformat.so
libavformat.so.57
libavformat.so.57.56.101
So I want to know why a later version of opencv requires an older version of libavcodec. Also, how can I installed both libavcodec56 and libavcodec57 on my machine ?
I use a raspberry pi with Raspbian Strech
Its not that opencv requires it, Its that whoever compiled the binary of opencv you are using compiled it against libavcodec56. Easiest fix is to compile it yourself.
Also, how can I installed both libavcodec56 and libavcodec57 on my machine ?
Don't. just compile and link against the same version.

PyDev import error even though module is installed

I'm trying to use the module pyelastix in PyDev but the line import pyelastix keeps yielding ImportError: No module named 'pyelastix'. I'm using a virtual environment called cv on Ubuntu 16.04. I tried the following commands to install pyelastix:
sudo pip install pyelastix
sudo pip3 install pyelastix
inside and outside of the virtual environment. Importing it in the CLI works fine:
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyelastix
>>>
In Eclipse, the PyDev Interpreter is set to /home/username/.virtualenvs/cv/bin/python3.5. The PYTHONPATH source folder is /${PROJECT_DIR_NAME}. What could be the issue here?

After miniconda 3.3.0 (anaconda) installation, I get no module named conda.cli error

I installed latest version of miniconda on a linux 64-bit filesystem that does not allow hard links (openAFS).
These are installation steps:
run installer until it fails on hard link errors
then modify install.py specified in $CONDA_INSTALL adding two line at the top of _link function
if linktype==HARD_LINK:
linktype=SOFT_LINK
now execute $PYTHON $CONDA_INSTALL --prefix=$PREFIX --pkgs-dir=$PREFIX/pkgs --link-all and everything works
The problem is that even if python is correctly installed,
> miniconda/bin/python
Python 2.7.6 |Continuum Analytics, Inc.| (default, Jan 17 2014, 10:13:17)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
I cannot run conda:
> miniconda/bin/conda
Traceback (most recent call last):
File "miniconda/bin/conda", line 3, in <module>
from conda.cli import main
ImportError: No module named conda.cli
I tried to set $PATH and/or $PYTHONPATH and/or $LD_LIBRARY_PATH but without success.
Is there a way to solve this issue? Is there a way to force soft link in place of hard link during installation?
Thanks,
Angelo

Categories

Resources