Trying to import Levenshtein on (Jupyter ipython + windows) - python

I'm new to python and Anaconda and I tried to run my code which contains Levenshtein import, however, it shows me this error:
ImportError Traceback (most recent call last)
<ipython-input-1-896847aaaa86> in <module>()
1 import pandas as pd
2 import numpy as np
----> 3 import Levenshtein as lv
4 import math
5 import re
ImportError: No module named 'Levenshtein'
Any recommendations regarding this, I owe you tons of thanks

The error happens because Anaconda does not ship with the Levenshtein package. You'll have to install it.
Usually, you want to install python packages on Jupyter Notebook by using the conda command. I was having trouble installing this package in particular on a Windows, however, simply because Windows Defender held out the process indefinitely.
The way I managed to install it as by using pip in Windows's cmd. First you have to figure out were the python executable from your Notebook is running.
In your notebook:
import sys
{sys.executable}
Copy the path the cell outputs, open the cmd. There, use the following command:
[PASTE THE PATH HERE] -m pip install python-levenshtein
After that you should be able to import Levenshtein.

Related

Use netcdf4 with Jupyter Notebook

I am Currently Working on my Bachelors Degree, where I am to do a Data-Analysis using Jupyter Notebook. Normally I only write "normal" Python and Java code.
For this I need to open .NC Files, and a quick Google search told me to use netcdf4. Within my Anaconda Manager this was not a problem, but I can't seem to get it to work within Jupyter.
Here you can see what I tried. I can do "import sys" and "!{sys.executable} -m pip install netcdf4" (which i got from another Stackoverflow Thread), but "import netcdf4 as nc" doesnt work. (Error Code
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-32-6eba77c50763> in <module>
----> 1 import netcdf4 as nc
ModuleNotFoundError: No module named 'netcdf4'
Can somebody tell me what I am doing wrong?
The netcdf4 package is not installed in your current environment. You could do the following in your notebook:
! pip install netcdf4
or conda install, depending on how you want to intall the package.
I found it out after hours of trial and error.
Of course its "!{sys.executable} -m pip install netcdf4" (netcdf all lowercase letters), but to install its "import netCDF4 as nc" (CDF capitalized).
Those are the days i'd rather have studied economics.

Used "pip3 install" to successfully installed "pytesseract", but when I try to import it at Jupyter Notebook, it failed on me

Once again, the "pip3 install" was successful
This is what the error message looks like:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-fb370059137a> in <module>
1 from PIL import Image
----> 2 import pytesseract
3 import sys
4 from pdf2image import convert_from_path
5 import os
ModuleNotFoundError: No module named 'pytesseract'
check which pip you are using for installation and also see where your Jupyter Notebook is reading from.
1- In the terminal (outside Jupyter), make sure that you can import the package. Note the path of your Python.
2- When in Jupyter Notebook, find your Python path with the following command and make sure they match:
import sys
print(sys.executable)
If the problem was not a PATH issue (which it seems it is!), you should figure out why it's not installed correctly.
Try installing Pillow package along with the pytesseract package
pip install pytesseract Pillow

Ipython does not see the installed library

I have a working Python 3.6 and the package imutils is recognized, importable in its shell. Today I installed some packages on my Python 2 for another task, and now my IPython does not recognize imutils anymore:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-b01afa4ab41d> in <module>()
4 import random
5 import math
----> 6 import imutils
7 import re
8 import time
ImportError: No module named imutils
What's going on? How fragile are these things, seriously.
I run sys.executable on both environments and the result is the same:
/usr/bin/python3
I checked my Python2 and the package is not installed there:
sudo -H pip2.7 uninstall imutils
Skipping imutils as it is not installed.
Doing this:
/usr/bin/python3 -V
Returns this:
Python 3.6.7
Restarting does not work. I did use sudo commands, installed, uninstalled several times - no luck. Something has screwed up my Python, I think.
P.S: I do use Python3 on my IPython as interpreter.
P.S: I don't use Python 3.4 as a kernel whatsoever, they are all 3.6.
EDIT: Okay it is clear that ROS installation screwed up my Python path since I see this:
os.getenv("PYTHONPATH")
'/home/user/ros_ws/devel/lib/python2.7/dist-packages:/opt/ros/melodic/lib/python2.7/dist-packages'
HOW CAN I SET IT BACK TO WHERE IT WAS BY DEFAULT?
It was due to the fact that ROS sourced its own Python version (2.7) by changing the PYTHONPATH.
Once I removed it from my .bashrc, it started to work again.

Python statsmodels and simple exponential smoothing in Jupyter and PyCharm

I am new to python, and trying to run this example in Jupyter notebook. Whenever I run following
import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from statsmodels.tsa.api import SimpleExpSmoothing
It gives me following error
ImportError Traceback (most recent call last)
<ipython-input-5-a15788c08ca7> in <module>()
3 import pandas as pd
4 import matplotlib.pyplot as plt
----> 5 from statsmodels.tsa.api import SimpleExpSmoothing
ImportError: cannot import name 'SimpleExpSmoothing'
Although, I have installed statsmodels (0.8.0) by
pip install statsmodels
like other packages (numpy, pandas etc.). I checked on git, api file contains this method but my api file (obtained through pip) doesn't have this method. Maybe I am not getting the git version (seems latest one) through pip? I am working in windows and I also tried on mac OSX, and result is same. I tried to do a copy/paste attempt for missing files/code in files from git (not a good way) but it doesn't help. I would appreciate your suggestions here.
EDIT
So the solution for Jupyter (thanks to #user333700) is to install master branch directly from git by
pip install git+https://github.com/statsmodels/statsmodels.git
I am extending my question for PyCharm, how can I add a git package within PyCharm? This link does not help.
For future reference another solution which worked for me is to pip install the latest version directly:
pip install statsmodels==0.9.0rc1

Anaconda cannot import scipy

Importing scipy in iPython gave me:
In [1]: import scipy
-----------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-4dc45f4c0083> in <module>()
----> 1 import scipy
/usr/local/lib/python2.7/site-packages/scipy/__init__.py in <module>()
/usr/local/lib/python2.7/site-packages/scipy/_lib/_ccallback.py in <module>()
ImportError: cannot import name _ccallback_c
In [2]:
Did a complete update of all the files of Anaconda
> conda update --all
and the error remains. Did a complete search on the web and there are similar problems but without solutions. Can you help me?
i am giving you two solutions which might work by my expereince
1. create a virtualenv and install the scipy package in that virtualenv and give path like this
import sys
sys.path.append('/home/shashi/.virtualenvs/venv/lib/python2.7/site-packages/')
import scipy
2.
Download the source code https://github.com/scipy/scipy/archive/v0.18.0-1.zipand unpack it. Open a command window in the folder where the setup.py of the module is located and type
scipy python setup.py install
It looks like scipy is not installed
conda install -c anaconda scipy
Try this and let us know if you receive the error again
Cheers!

Categories

Resources