Error ModuleNotFoundError: No module named 'pdf2docx' - python

I am having an issue to work with the lib pdf2docx.
Here is the code I am trying to work
from pdf2docx import Converter
pdf_file = 'test_file.pdf'
docx_file = 'test_file.docx'
# convert pdf to docx
cv = Converter(pdf_file)
cv.convert(docx_file, start=0, end=None)
cv.close()
I have installed the lib using pip install pdf2docx and I have tried as well to use sudo.
I tried to use as venv like:
create a folder
inside this folder, open your command line(cmd)
pip install virtualenv
virtualenv venv
pip install pdf2docx
Any idea about how I can make the script working?

Require Python >= 3.6. pdf2docx can be installed through:
python3 -m pip install pdf2docx

I just solved the issue, it looks like I am unable to run the script using Vstudio. The script works using the command line like python3 pdf_to_docx.py.

Related

how to import modules like matplotlab in PyCharm

import random
import matplotlib.pyplot as plt
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
freq = {c: random.randint(1, 100) for c in alphabet if random.randint(1, 10) > 2}
print(len(freq))
print(freq)
plt.bar(range(len(freq)), freq.values(), align='center')
plt.xticks(range(len(freq)), freq.keys())
plt.show()
I received a code which uses matplotlib, I already installed it like here in console (in Git Bash) and searched for matplotlib under settings - modules, but found just two other and installed them (aliasimports/live coding in python). I still become this error:
ModuleNotFoundError: No module named 'matplotlib'
In Pycharm File -> View -> Tools Windows -> Python packages
It will list all installed packages, search for Matplotlib and install it.
If you are running in terminal:
python -m pip install matplotlib
If on unix:
locate your python, which python
python_path/bin/python -m pip install matplotlib
If you are using python2, without pip. Install it
wget https://bootstrap.pypa.io/get-pip.py
After saving above file, run
python get-pip.py
Now run pip install command.
If your script is using shebang, do include this line at top of your file
#!/path/to/your/path/binary
before using any library in python you need to install it. for installation there are different methods(depend on OS) but simple way is PIP INSTALL PKG_NAME

Unable to use patoolib after 'pip3 install patool'

I am using a macbook, and have python3 installed and using spyder.
I have installed patool and it's listed in pip3 list.
When I import patoolib and run the program it says, ModuleNotFoundError: No module named 'patoolib'
So I am not able to run the extract related programs.
import patoolib
import os
import glob
def extract_files(inputdir = '/Users/satishvadlamudi/Python_spyder_projects/zipped',outputdir = '/Users/satishvadlamudi/Python_spyder_projects/extracted'):
os.chdir(inputdir)
archives = glob.glob('*.gz')
#print(archives)
if not os.path.exists(outputdir):
os.mkdirs(outputdir)
files = os.listdir('/Users/satishvadlamudi/Python_spyder_projects/extracted')
print (files)
for archive in archives:
if archive[:-3] not in files:
patoolib.extract_archive(archive, outdir = outputdir)
Note that "pip" is also a python module. If you see pip3 list give you the module installed but python3 complaint about ModuleNotFoundError, you may want to check if pip3 and python3 mean the same thing.
Try with python3 -m pip list -v, which the -v tells you the installed location as well. If you see the module there, then the same python3 interpretor should be able to find the module. If not, you may want to consider setting up PYTHONPATH env variable.
In order to import :
import patoolib
you need to install patool first :
pip install patool

Python: ModuleNotFound Error

I downloaded multiple modules (Discord API, cx_Freeze) (pip download, Windows 10) and now I wanted to use them.
But when I want to import them, it says there isn’t any module.
From my former Python using (before resetting computer) I‘ve added a pycache folder and it worked for one module. I‘m not able to reproduce it for other modules. What to do?
I‘ve only one Python version (3.6.5) on PC.
I‘ve checked the \site-packages folder and they‘re there.
If you are using python3 then try downloading the library using
pip3 install libname
but if you are using python2 then install the library using
pip2 install libname or just pip install libname
try with these command and reply
try installing your library using the command prompt in normal user and with the admin user so that you will get to know that what is happening and also if it is still not working then try installing the library into the same folder of your project using pip custom install command
pip install -t <direct directory> <package>
then use the import statement
For Example I used
pip2 install -t c:\Users\Nav\Desktop\projectss cx_freeze
then i imported the library using
#from cx_Freeze import setup, Executable
import cx_Freeze
from cx_Freeze import *
it worked.
Previously i was getting error like :
File "C:\Python27\lib\site-packages\cx_Freeze\__init__.py", line 10, in <module>
from cx_Freeze.finder import *
ImportError: No module named finder
After custom install it is working

Import error installing tlslite

I'm trying to install tlslite. After installed the module I've tried to test it and I receive this error:
from .checker import Checker
ImportError: No module named checker
I've checked on my pip module list and checker is installed...
Any idea?
Thanks!
Assuming you installed tlslite correctly, try this:
>>> from tlslite.checker import Checker
If that doesn't work, check that tlslite is in your site packages
To work with tlslite I recommend to use a virtualenv and install TlsLite inside:
cd ~/virtualenv/ # <- all my virtualenv are here
virtualenv myvenv
source ~/virtualenv/myvenv/bin/activate
pip install -q -U pip setuptools # ensure last version
pip install tlslite
With that in hand, you can use the Checker:
$ python
>>> from tlslite.checker import Checker
>>>
Et voilà !

xlrd import issue with Python 2.7

I have an assignment to read excel data in Python. I have Python 2.7 installed. I tried installing xlrd0.8.0 with the following commands in Windows.
C:\Python27\xlrd-0.8.0>python setup.py build
running build
running build_py
creating build
creating build\lib
creating build\lib\xlrd
copying xlrd\biffh.py -> build\lib\xlrd
....
C:\Python27\xlrd-0.8.0>python setup.py install
running install
running build
running build_py
running build_scripts
running install_lib
running install_scripts
running install_egg_info
Writing C:\Python27\Lib\site-packages\xlrd-0.8.0-py2.7.egg-info
I don't get any error message while installing. I also see xlrd-0.8.0 folder in site-packages in /lib folder...
But when I try to import it, Python is not able to recognize it...
>>> import xlrd
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import xlrd
ImportError: No module named xlrd
Can you suggest how to find the issue?
How to reproduce and fix this error:
Open the python interpreter, try to import xlrt, you get an error:
python
>>> import xlrt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named xlrt
1. Install, or make sure pip is installed:
What is the official "preferred" way to install pip and virtualenv systemwide?
2. Install xlrd
pip install xlrd
Protip: If you feel you have to use sudo pip install .... to get this to work then you need to stop and learn why this is dangerous. See: What are the risks of running 'sudo pip'?
Workarounds are to install pip using a certain user: pip install --user myuser ... use your own best judgment here. Make sure the directory your pip is operating in is owned by the user trying to install packages there. Use: chown -R $USER /Library/Python/2.7/site-packages.
3. Test it on the python interpreter:
python
>>> import xlrd
>>> type(xlrd)
<type 'module'>
>>>
Now it is imported it without a problem, xlrd is a python module.
Troubleshooting:
If your PYTHONPATH is not defined, you should define it:
PYTHONPATH=:/home/el/wherever/where_to_find_modules
Resolving issue with xlrd import in Python 2.7
open this link https://bootstrap.pypa.io/get-pip.py and save as get-pip.py and copy this file into C:\Python2.7\
C:\Python2.7\python.exe get-pip.py
After this pip is installed in your system now installing xlrd
C:\Python2.7\python.exe -m pip install xlrd
Open python and import xlrd
import xlrd
it will work.
For me, running python in spyder on a mac, it didn't work even after I installed xlrd using pip, because it was installed to a different location than the one spyder was using. To fix this, I first found where xlrd was installed to:
$pip install xlrd
Requirement already satisfied: xlrd in /usr/local/lib/python2.7/site-packages
Then copied the xlrd folder from there into where Spyder could access it:
$cd /Applications/Spyder.app/Contents/Resources/lib/python2.7/
$cp -r /usr/local/lib/python2.7/site-packages/xlrd.
Then updated the module within spyder, but I'm not sure whether this was necessary. Restarting Spyder might have also worked after making those changes.
If you're using conda,
conda install xlrd
Please add "C:\Python27\Lib\site-packages\" to your PYTHONPATH in your system variables.
If there is no such SYSTEM VARIABLE, please create it:
Right-click the My Computer icon on your desktop and select Properties.
Click the Advanced tab, then click the Environment Variables button.
Under System Variables, click New.
Enter the variable name as PYTHONPATH.
Enter the variable value as C:\Python27\Lib\site-packages\
Click OK.
Click Apply Changes.
I had the same problem, seems like the is better if you export your xlsx to a csv file and then run the following on python
df = pd.read_csv('FileName.csv')
It should work like that. If you're using iPython or even better Jupyter then run df.head() to check if pandas reads your table properly.
Note, I am using Ubuntu
python -m pip install xlrd
For my case I have both python2 and python3 installed, pip install xlrd default install xlrd into the Python3 library (/usr/local/lib/python3.6/site-packages/xlrd/. By specifying python2 for pip install solved my problem.

Categories