ImportError: No module named pynotify. While the module is installed - python

So this error keeps coming back.
Everytime I try to tun the script it returns saying:
Traceback (most recent call last):
File "cli.py", line 11, in <module>
import pynotify
ImportError: No module named pynotify
The strange thing is, I just installed this plugin.
I also restarted command prompt already, even the computer.
But nothing, if anyone could help me out here that'd be great!

Try this:
pip install py-notify
It worked for me.

You are most likely looking for pyinotify not pynotify. That should fix your ImportError.

Here is the solution for Ubuntu.
First install python-notify: sudo apt-get install python-notify
After that you may need to add the right paths:
import sys
sys.path.append('/usr/lib/python2.7/dist-packages/gtk-2.0')
sys.path.append('/usr/lib/python2.7/dist-packages/')
Finally: import pynotify

first check your pipversion and your python running version
pip --version, python --version
if the pip is from python3's packages. and you python environment is running at python2.x. so abandon using your pip to install any notify , you just install python-notify

If what you install is py-notify (http://home.gna.org/py-notify/), it should be:
import notify

Check whether you were using the corresponding pip version for your version of Python. For example, if you have Python2 and Python3 installed, you may have installed pynotify for Python2, and attempting to import it from Python3, which will result in the package not being found.
Try running
pip --version
Assuming pip install is how you installed the package as well as
python --version
to ensure the version numbers are similar.

Import package 'notify' instead of 'pynotify'
import notify

This error is because, you had run the Python file (mitmf.py) with python2. But you have installed pyinotify in python3-pip. So it will only run in pip2.To install it follow the link... https://linuxize.com/post/how-to-install-pip-on-ubuntu-20.04/

Related

ModuleNotFound error but module has just been installed

I'm using Windows 10, Python 3.6.4. I'm trying to use the module Pyperclip and have installed it with pip:
c:\Users\Bertie>pip install pyperclip
Requirement already satisfired: pyperclip in c:\python36\lib\site-packages (1.8.0)
But when I try to run a program which uses this module, I get this error:
c:\Users\Bertie\scraping.py test
Traceback (most recent call last):
File "C:\Users\Bertie\scraping.py", line 3, in <module>
import webbrowser, sys, pyperclip
ModuleNotFoundError: No module named 'pyperclip'
How can I fix this? Thank you.
The reinstall trace shows you install the packge successflly for python36.
Check if there is more than one python in your system. Type "python" in your windows cmd console, and check the python version to see if python36 is the default one. Then explicitly use the python interpreter to start the script "python your_python_script.py".
Where is the py file? Maybe try cd-ing into the folder and run python (python3) scraping.py?
Also check that you have installed the correct interpreter and are using the correct version of python.
Maybe You Installed pyperclip in conda env or a virtualenv and you forgot to activate it ?
Because This Has Happened To Me Many Times.
Or Maybe You Have 2 Instances Of Python installed on your computer and you accidentally installed pyperclip in the other instance of python ?

ModuleNotFoundError: No module named 'pynput' Python3 and pip3

I want to use 'pynput', so I used pip to add it to my environment.
The installation proceeds without problem.
But I am unable to import it into my project.
I am using python 3.8.1 on my environment.
I used pip3 for installation.
I have already tried to install pynput, uninstall it and reinstall it multiple times.
My .py file doesn't have a confusing name like "pynput.py"
I am comfortable with my environment when I try to execute my file.
I am trying to run from my terminal or VSCodium, and neither of them works.
And I work on Debian 10.
pip freeze :
pynput==1.6.7
python-xlib==0.26
six==1.14.0
Traceback :
Traceback (most recent call last):
File "./play.py", line 6, in <module>
from pynput import keyboard
ModuleNotFoundError: No module named 'pynput'
So I don't understand why it doesn't work.
thank you in advance for your help :)
When creating my project, I was not working under an environment, so I used the classic shebang: #!/bin/python3.
Then, I went under an environment to use pynput, but I just forgot to change my shebang to #!/usr/bin/env python.
So, actually, I didn't risk finding pynput
It might be possible you have two versions. Rry installing with python3 -m pip install pynput or you should use some older version of Python. I am using 3.7.5 and its works perfect for me.
Try importing from the terminal.

ModuleNotFoundError: No module named 'ruamel'

I'm using a Kubernetes inventory builder script found here: https://github.com/kubernetes-sigs/kubespray/blob/master/contrib/inventory_builder/inventory.py
On line 36, the ruamel YML library is imported using the code from ruamel.yaml import YAML. This library can be found here: https://pypi.org/project/ruamel.yaml/
On my OSX device (Mojave 10.14.3), if I run pip list, I can clearly see the most up to date version of ruamel.yaml:
If I run pip show ruamel.yaml, I get the following output:
I'm running the script with this command: CONFIG_FILE=inventory/mycluster/hosts.ini python3 contrib/inventory_builder/inventory.py 10.0.0.1 10.0.0.2 10.0.0.4 10.0.0.5
Bizarrely, it returns the following error:
Traceback (most recent call last):
File "contrib/inventory_builder/inventory.py", line 36, in <module>
from ruamel.yaml import YAML
ModuleNotFoundError: No module named 'ruamel'
I have very little experience with Python, so don't understand how this could be failing. Have I installed the library incorrectly or something? From the documentation on the ruamel.yml project page, it looks like the script is calling the library as it should be.
Thanks in advance
In my case, I was installing this with pip3 install ruamel.yaml, and it was puting the package in /usr/local/lib/python3.9/site-packages/, but the python3 binary on the machine was pinned to Python 3.7, so trying to import that module was sending the ModuleNotFoundError message.
What helped to fix this, was to install the module with python3 -m pip install ruamel.yaml, running pip via the python3 binary makes sure it runs on the same version, in this case 3.7, and gets installed via the correct version number site-packages.
pip is set to point to the Python 2 installation. To install the library under Python 3, do pip3 install ruamel.yml.
you're using python 3 and want to use the package that is with python 2. Go to the directory where your python 3 is, navigate to Scripts and use the pip in there to install the needed library.
This helped me (adding version number to python):
CONFIG_FILE=inventory/mycluster/hosts.yaml python3.6 contrib/inventory_builder/inventory.py ${IPS[#]}
[python 3.10.x].
There is no package called ruamel.yaml
what worked is pip install ruamel-yaml

Python cannot import openpyxl

I am running Windows 7 and using Python 2.7.
I have installed openpyxl using easy_install. It looks like the installation was successful. I changed the directory and fired up Python.
>>> import openpyxl
>>>
So, this should mean that Python is able to find openpyxl. However, when I execute a simple test program excell_tutorial1.py and run it, I get the following:
Traceback (most recent call last):
File "C:/Python27/playground/excell_tutorial1.py", line 7, in <module>
from openpyxl import Workbook
ImportError: No module named openpyxl
Very confusing! It could find it in prompt line but not in the program!
import os, sys
the_module ="C:\\Python27\\Lib\\site-packages\\openpyxl-2.3.3-py2.7.egg\\openpyxl"
if the_module not in sys.path:
sys.path.append(the_module)
if the_module in sys.path:
print sys.path.index(the_module)
print sys.path[18]
so, this gives me:
18
C:\Python27\Lib\site-packages\openpyxl-2.3.3-py2.7.egg\openpyxl
Anyone can think of what the problem might be?
Much appreciated
I had the same problem solved using instead of pip or easy install one of the following commands :
sudo apt-get install python-openpyxl
sudo apt-get install python3-openpyxl
The sudo command also works better for other packages.
While not quite what you ran into here (since you state that you are using python 2.7), for those who run into this issue and are using python 3, you may be unintentionally installing to python 2 instead. To force the install to python 3 (instead of 2) use pip3 instead.
See this thread for more info:
No module named 'openpyxl' - Python 3.4 - Ubuntu
Try deleting all openpyxl material from C:\Python27\Lib\site-packages\
Once you do that try reinstalling it using pip. (This what worked for me)
At times this can be a simple permission issue. As it was in my case. I installed it in my local directory with my login.
python ./setup.py install
but some of the other user were not able to import the module.
They were getting this error:
ImportError: No module named openpyxl
Hence I simply gave exe permission to 'others'
chmod -R 755
That solves the problem at least in my case.
Go to the directory where pip is installed, for eg.C:\Python27\Scripts and open cmd (simply type cmd in address bar ). Now run the command "pip install openpyxl". It will install the package itself. Hope this will solve your problem.
Try this:
!pip install openpyxl
I had the same issue on 3.8.2
I found out that python was installed in two locations on my machine (probably py and python, just a guess)
Here:
C:\Users<userAccount>\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8\LocalCache\local-packages\Python38
and Here:
C:\Python38
I deleted the one in my C drive and everything is working well now. I would double check to see where your packages are getting installed first, before deleting. Which ever one is being used, keep that one.
For this case, check to see where this package got installed:
C:\Users\<userAccount>\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8\LocalCache\local-packages\Python38\site-packages\openpyxl
keep that directory.
What worked for me was to open the terminal as an administrator, cd to the 'scripts' file of where python (different for each version) is stored, and then install using pip:
cd C:\Users\Salfa\AppData\Local\Programs\Python\Python39\Scripts
pip install openpyxl
This resolved the problem for me.

pyserial: No module named tools

I have installed the latest pySerial on my Ubuntu box with python 2.7.2, and it works fine for most things, but whenever I try to import the 'tools' package, it says that it can't find 'tools'. The documentation for pySerial explicitly references this 'tools' package.
>>> from serial import tools
Traceback (most recent call last):
File "<pyshell#30>", line 1, in <module>
import serial.tools
ImportError: No module named tools
and when I:
>>> serial.VERSION
'2.5'
which is the latest version according to Source Forge
So why can't I get to the 'tools' package of pySerial?
Use pip to install pyserial. First install pip:
sudo apt-get install python-pip
After that install pyserial:
sudo pip install pyserial
You have to uninstall serial and pyserial then reinstall pyserial:
pip uninstall serial
pip uninstall pyserial
pip install pyserial
Because the both libs contain a file named serial.py, you get a name conflict.
I got here because I had the same problem.
The strange thing was that
import serial
worked, but
from serial.tools import list_ports
didn't.
Turns out stupid me named the script "serial.py". After renaming it everything worked.
It looks like the ubuntu package does not quite match up with upstream. compare the official pySerial package on their SVN:
http://pyserial.svn.sourceforge.net/viewvc/pyserial/trunk/pyserial/serial/
to the ubuntu package in launchpad:
http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/raring/pyserial/raring/files/head:/serial/
Tools is missing there, too. It does look like they keep the miniterm.py script, and install it... somewhere; I'm not versed enough in deb packaging to understand where, though.
The pyserial-2.4-py2.7.egg in the site-packages folder was getting imported instead of from serial in the site-packages folder. Once I renamed this file so that it no longer imported from this it worked fine. You can easily debug this by doing
import serial
serial._ _path_ _
to see where serial is getting imported from.
In my case, I installed serial but not pyserial after getting the following error.
ImportError: No module named 'serial'
Then import serial was ok, but from serial import tools can't work.
Just sudo pip uninstall serial and sudo pip install pyserial
Hope to help people like me.
yes,use python-pip install ,,,then ,,,upgrade,,,the version of serial will be 2.7 ...it workes
Just in case that doing "pip install --upgrade" doesn't work(as happened to me), in Linux you can check if you have a serial package in /usr/lib/python2.7/dist-packages, the new serial packaged the one that pip install goes to /usr/**local**/lib/python2.7/dist-packages/serial, for some reason the one in usr/lib/python2.7/ has precedence and the module tools doesn't exist in that version of pyserial. Changing names or deleting the directory solve the problem.
the difference between pip and python -m pip can be the version. for example, it may be that you call pip from python2, but when you type python -m pip then you get python3 and so on...
You have to call the functions of module this way:
from serials import tools
For example: If I want to call sqrt function from math module, I would do:
from math import sqrt
import math.sqrt **is wrong.**
From the pyserial webpage: https://pyserial.readthedocs.io/en/latest/pyserial.html
They recommend that you use the command:
python -m pip install pyserial
That worked for me. I don't know enough about pip to undersand the difference from just a regular pip install pyserial, but it worked for me (after much frustration).

Categories