Python cannot import openpyxl - python

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.

Related

No module called 'discord' found

I'm trying to make a discord bot. So I did 'pip install discord' and it installed successfully! I have added Python to PATH as well. now in the Python Shell, I typed, 'import discord'. Then I get this error:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import discord
ModuleNotFoundError: No module named 'discord'
I have used 'pip install discord' again and again and it still doesn't work! My pip is also the latest version. I also uninstalled and installed python but still doesn't work! :(
Why does it not work? Please help me. Thanks!!
I think this is because it is
pip install discord.py and not
pip install discord.
If you are on Linux, try pip3 install discord.py (pip installs to python2 by default).
You can also see the official pypi project.
This should be a simple solution. A previous answer indicated to make sure that you use the correct, full module name when making the pip call to install the module, and this is imperative -- however, since you're still not seeing results there is clearly still an issue.
The first question is what is your python download? Did you install python through something like conda, or did you just install the language directly on your device without a facilitating package?
In the meantime (and especially if you don't know the answer to the above question), try this command in your terminal (not your python shell, just your command line):
pip freeze
This command is referenced from this link, in case you're curious, and should give you a list of all locally install non-default python packages. If you provide the result of this call, I am certain it will better facilitate the solving of this issue.
Me to, I got this error.
I solved it as follows:
import discord.abc
if you use linux and run the pip install command as non root but the start command as root you need to run the pip command also as root

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.

using netcdf without installation

I need to use netcdf but do not have install permission for python modules. I have downloaded netcdf-0.1.2.tar.gz from here: https://pypi.python.org/simple/netcdf/ and unzipped the tar ball. I have been following this stack overflow post in an attempt to use the module but have had no luck so far:
(Python) Use a library locally instead of installing it
here is what I have tried:
Installing virtualenv:
I do not have permission to do this
python setup.py install -- user:
again, I don't have permission
running my script with netcdf as my current working directory:
I tried this as well, here are the issues I have run into:
first I went into netcdf-0.1.2 and made a new file called asdf.py
which contains the following:
import netcdf
print("testing")
running python asdf.py gives the following error:
Traceback (most recent call last):
File "asdf.py", line 1, in <module>
import netcdf
File "/.../Downloads/netcdf-0.1.2/netcdf/__init__.py", line 1, in <module>
from netcdf import *
File "/.../Downloads/netcdf-0.1.2/netcdf/netcdf.py", line 1, in <module>
from netCDF4 import Dataset, numpy
ImportError: No module named netCDF4
I'm not sure how to fix this error, any help would be greatly appreciated
in case this is somehow relevant, the version of Linux I am using is 3.2.0-23-generic
also I have numpy installed already
Easest would be to install Anaconda or Miniconda with your user rights.
Anaconda already as netCDF4installed. In case of Miniconda install with:
conda install netcdf4
If you have Python 3 installed, then you will have the venv package in the standard library, so you do not need "virtualenv" to be installed for you separately (as would be the case with Python 2). Instead use python3 -mvenv , in a similar way to how you would use virtualenv, for example:
python3 -mvenv /path/to/my_venv
or to include any non-standard packages already installed on the system:
python3 -mvenv --system-site-packages /path/to/my_venv
After that, you should be able to activate the environment and pip install packages, e.g.
source /path/to/my_venv/bin/activate # for csh use activate.csh instead
pip install netCDF4
Remember to source the activate script at run time as well as installation time:
source /path/to/my_venv/bin/activate
python
and you should then find that in your python session you have the netCDF4 package available, e.g.
import netCDF4
my_dataset = netCDF4.Dataset('myfile.nc')
Of course, substitute the actual path in place of /path/to/my_venv above.
None of this requires any root privileges.
(And as someone else has suggested, another option for you is to use conda.)
I'd also like to highlight that the package is imported using capitals
import netCDF4 as nc
This might not matter on a mac, but for Windows it is key.

no module named 'numpy' (windows 7, python 3.4.3, numpy-1.9.2)

Please only respond to this post if you use Python on Windows, rather than Mac or Linux.
Error message:
>>> import numpy
Traceback (most recent call last):
File "stdin", line 1, in <module>
ImportError: No module named 'numpy'
Questions:
Regarding windows 7, python 3.4.3 and numpy-1.9.2, are there any
conflicts that would prevent these from working together?
Into which directory (please write out the complete directory path
starting with "C:") should I extract the contents of the numpy zip
file?
What is the exact command that I need to type into python command
prompt in order to install numpy?
Thanks in advance for your assistance
I was also facing this issue where in I tried using
import numpy
But it has given me error "ImportError: No module named 'numpy'"
I installed numpy using "C:\user>python -mpip install numpy" and it was successfully installed.
However I was again getting the same error
Then I checked that the path where in numpy was intalled was not listed in
import sys
print(sys.path)
Then I appended my path wherein numpy was installed using ">>> sys.path.append(r"C:\Users\xxxx\AppData\Roaming\Python\Python38\site-packages").
The above command worked fine, still problem not resolved then I restarted my python session again.
Finally it worked..!!!!(As after every append we have to restart our python session).
1) No there isn't.
2) You can use pip. pip install numpy
If you don't have pip installed, install it, its the most often used way of installing python packages. Yes it is possible to do under windows.
3) Once you have the python command prompt, you already have python installed.
1) no
2) It doesn't actually matter as pip or the installer will figure that out for you. However, just so you know, pip or whatever will install numpy into your site-packages folder.
3) I recommend downloading the NumPy installer from SourceForge:
http://sourceforge.net/projects/numpy/files/NumPy/1.9.2/
Then you don't have to worry about having the right compiler installed. However, if you want to use pip, then you'll need to install the appropriate compiler. This is documented at the following locations:
Microsoft Visual C++ Compiler for Python 3.4
https://matthew-brett.github.io/pydagogue/python_msvc.html
I'm not even close to an expert on Python. That said, I like the notion of "keep it simple." I chose to install a Python distribution that already includes numpy. Specifially I installed Python(x,y). Everything seems to be working just fine right after install. I appreciate all those who commented on my question. Thanks

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

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/

Categories