I am attempting to Import PyPDF2 in order to read a PDF file and parse through it. I am using a Raspberry Pi, and have installed PyPDF2 using the command pip install PyPDF2. However, when I try importing it, I am getting ModuleNotFoundError.
I think it may have installed it into the wrong location. When I do python -V it says I am using version 2.7.16. But the error states it's trying to look into the python3 folder?
I am attempting to import it using the line import PyPDF2
The error I'm getting is:
Traceback (most recent call last):
File "/home/pi/SqlDatabase.py", line 5, in <module>
import PyPDF2
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 305, in _custom_import
module = self._original_import(*args, **kw)
ModuleNotFoundError: No module named 'PyPDF2'
Any idea of how I can install PyPDF into the correct directory, or perhaps a different solution?
If you are starting the program with python3 (e.g. see if the first line of the file has #!/usr/bin/python3 or similar), you need to install the library with pip3.
It seems that you have not installed PyPDF2 module in your device.
Execute following code in your terminal:
pip install PyPDF2
or
pip3 install PyPDF2
I think this will solve your problem. If this does not solve your problem, then there may be problem in your directory of python.
I have also faced the same issue. Note that Python is a case-sensitive language.
While using the import command use PyPDF2 and not pyPDF2
To install:
pipenv install PyPDF2
To import:
import PyPDF2
Related
So, I'm a bit new to python and have mastered javascript.
I know that javascript modules are saved in node_modules folder in a directory
I did: $ pip install pyautogui
but when I'm about to run my code, it says :
'Traceback (most recent call last):
File "bruh.py", line 1, in <module>
import pyautogui, time
ImportError: No module named pyautogui'
where do python modules get saved to? 'python_modules' folder?????
also, idk what to do, can anyone help me with this error?
To see the path where your modules are saved once you pip them.
You can open a python shell, import sys and print the sys.path variable. One of the path would end with site-packages, thats the path where modules are saved.
$ python3
>>> import sys
>>> print(sys.path)
[‘’, ‘/Users/uname/.local/lib/python3.6/site-packages/‘]
could be a number of things. do you have multiple versions of python on your machine? If so you'd need to pip install to the correct python version, e.g.:
pip3 install pyautogui vs pip install pyautogui
So I was using Python IDLE to create my codes, created an environment variable to run the code from run window outside of idle and it was working fine. Recently I downloaded Anaconda for a class and when I try to run a code from outside of idle I get the below message error. Is there a way to change the directory which python is looking for packages to a different path as I assume once I downloaded Anaconda the path has changed. I appreciate you help.
Here is my traceback
File "C:\Users\h.omail\MyPythonScripts\RFQs.py", line 1, in <module>
import os, os.path, docx, win32com.client, shutil, send2trash, PyPDF2, textract, re, pprint
File "C:\Users\h.omail\Anaconda3\lib\site-packages\docx\__init__.py", line 3, in <module>
from docx.api import Document # noqa
ImportError: DLL load failed while importing etree: The specified module could not be found.
pip install python-docx
OR
pip3 install python-docx
I am trying to use the dnspython in my code but when it gets to the import statement, I get the following error:
>>> import DNS.resolver
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\python27\lib\site-packages\DNS\resolver.py", line 31, in <module>
import dns.exception
ImportError: No module named dns.exception
I have tried installing with pip, easy_install and manually from the git repo but nothing seems to do the trick. Any ideas??
Code:
import DNS.resolver
if __name__ == "__main__":
domain = 'hotmail.com'
for x in dns.resolver.query(domain, 'MX'):
print x.to_text()
Another thing you can do to fix problems with this package is to install python-dnspython again using Synaptic. (Whether no having previous problems about duplicity)
Sometimes if you try to install this package using pip could appear some problems like that:
Command python setup.py egg_info failed with error code 1 in
/tmp/pip_build_root/dnspython Storing debug log for failure in
/root/.pip/pip.log
Using Synaptic cleans the old files and install the new ones, from that package. I know this issue is solved but I wanted to add more information about this :)
That's because package and module names are lowercase (see PEP 8). This works just fine :
import dns.resolver
import dns.exception
You should also be careful that none of your own *.py filename conflicts with the dns package. Your *.py file should not be named dns.py. Pay also attention to the *.pyc files.
First, your code should be : import dns.resolver.
There seems to be an issue installing dnspython using pip, you should clone the dnspython repository using git and run the file setup.py as follows:
git clone https://github.com/rthalley/dnspython
cd dnspython\
python setup.py install
If you don't have git installed on your machine, you can just download the repository manually .
when I import docx I have this error:
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/docx-0.2.4-py3.3.egg/docx.py", line 30, in <module>
from exceptions import PendingDeprecationWarning
ImportError: No module named 'exceptions'
How to fix this error (python3.3, docx 0.2.4)?
If you are using python 3x don't do pip install docx instead go for
pip install python-docx
It is compatible with python 3.x
Official Documentation available here: https://pypi.org/project/python-docx/
When want to use import docx, be sure to install python-docx, not docx.You can install the module by running pip install python-docx.
The installation name docx is for a different module
However,
when you are going to import the python-docx module,
you’ll need to run
import docx, not import python-docx.
if still you want to use docx module then:
First of all, you will need to make sure that the docx module is installed.
If not then simply run pip install docx.
If it shows '*requirement already satisfied*'
then the solution is :
Go to the library to find docx.py file,
you'll need to go to directory where you installed python then \Lib\site-packages\ and find docx.py file
Open docx.py file in text editor and find this code
from exceptions import PendingDeprecationWarning
Replace the above code with
try:
from exceptions import PendingDeprecationWarning
except ImportError:
pass
Save the file
Now you can run import docx module in Python 3.x without any problem
Uninstall docx module with pip uninstall docx
Download python_docx-0.8.6-py2.py3-none-any.whl file from http://www.lfd.uci.edu/~gohlke/pythonlibs/
Run pip install python_docx-0.8.6-py2.py3-none-any.whl to reinstall docx.
This solved the above import error smoothly for me.
If you're using python 3.x, Make sure you have both python-docx & docx installed.
Installing python-docx :
pip install python-docx
Installing docx :
pip install docx
You may be install docx, not python-docx
You can see this for install python-docx
http://python-docx.readthedocs.io/en/latest/user/install.html#install
In Python 3 exceptions module was removed and all standard exceptions were moved to builtin module. Thus meaning that there is no more need to do explicit import of any standard exceptions.
copied from
pip install python-docx
this worked for me, try installing with admin mode
The problem, as was noted previously in comments, is the docx module was not compatible with Python 3. It was fixed in this pull-request on github: https://github.com/mikemaccana/python-docx/pull/67
Since the exception is now built-in, the solution is to not import it.
docx.py
## -27,7 +27,12 ##
except ImportError:
TAGS = {}
-from exceptions import PendingDeprecationWarning
+# Handle PendingDeprecationWarning causing an ImportError if using Python 3
+try:
+ from exceptions import PendingDeprecationWarning
+except ImportError:
+ pass
+
from warnings import warn
import logging
I had the same problem, but pip install python-docx worked for me, I'm using python 3.7.1
You need to make it work with python3.
sudo pip3 install python-docx
This installation worked for me in Python3 without any further additions.
python3
>> import docx
PS: Note that the 'pip install python-docx' or apt-get python3-docx are not useful.
I had the same problem, after installing docx module, got a bunch of errors regarding docx, .oxml and lxml...seems that for my case the package was installed in this folder:
C:\Program Files\Python3.7\Lib\site-packages
and I moved it one step back, to:
C:\Program Files\Python3.7\Lib
and this solved the issue.
Had faced similar issue and found a work around have posted answer aswell under similar question find its link :https://stackoverflow.com/a/74609166/17385292
python imports exceptions module by itself
comment out import line. it worked for me.
python noob here. Just start picking up python few weeks ago and currently need some help. I have 3.3.4 python for windows 7 and I tried running this:
import urllib.request
from googlevoice import Voice
from googlevoice.util import input
import time
File "<pyshell#0>", line 1, in <module>
from googlevoice import Voice
ImportError: No module named 'googlevoice'
so I figured. no big deal, I just need to install the module. I obtained a setup.py file from the link below and ran the file in different directories. Then tried " import googlevoice" but still doesn't work. The github link isn't too helpful, in terms of installing this module. Please help? I think I just have not learned how to install modules properly. Last time it took me a while to install pygame module, but i think it was because of directory issues at first.
https://pygooglevoice.googlecode.com/hg/
http://sphinxdoc.github.io/pygooglevoice/examples.html
To install the PyGoogleVoice, you need to download the whole archive and execute:
python setup.py install
If you have pip install, you can also run pip install pygooglevoice, or easy_install pygooglevoice with EasyInstall, without having to download the source code.