I can't unpack a .rar file using patoolib in Python.
I always get the error message:
PatoolError: could not find an executable program to extract format rar; candidates are (rar,unrar,7z),
I'm using macOS, Anaconda Navigator with Spyder IDE, and I have already installed unrar package. I don't understand why patool can't find the executable program and I'm not able to solve this problem.
Can someone tell me how to solve?
EDIT:
The error arises when I call this method, that I defined to unpack both .zip and .rar files:
def unzip_file(path_to_file, out_dir):
# Extracts path_to_file in out_dir
if path_to_file[-3:] == 'zip':
with zipfile.ZipFile(path_to_file, 'r') as zip_ref:
zip_ref.extractall(out_dir)
return
if path_to_file[-3:] == 'rar':
patoolib.extract_archive(path_to_file, outdir=out_dir)
return
raise FileNotFoundError(path_to_file)
You're on macOS, you should probably installHomebrew if it's not installed, and then run brew install 7z and try again.
I'm guessing that this tool you're using doesn't do the actual archiving, it just knows how to talk to the various archive programs out there, and so you need to have installed one that can read and write RAR archives.
Related
I have created a functional python (Python 3.10.4) script that uses Pybluez (version 0.30) to connect to an ESP32. Now I want to use PyInstaller to create a standalone executable application from said script, but I keep running into the following error when executing the command:
pyinstaller scriptname.py
Error:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\X\Python3\lib\site-packages\pybluez-0.30-py3.10-win-amd64.egg\bluetooth\widcomm.py'
In the Python3\lib\site-packages directory, there is a pybluez-0.30-py3.10-win-amd64.egg file, but it contains no sub folders (bluetooth\widcomm.py).
Any help regarding this error would be much appreciated. Let me know if any additional information is required.
Thank You
Try to reinstall Pybluez and use a stable version, e.g. pybluez==0.23, or add widcomm.py manually https://github.com/pybluez/pybluez/blob/master/bluetooth/widcomm.py.
I managed to solve the mentioned problem, and here is how.
An .egg file is basically like a zip file that contains sub folders and files. I had to download a software called ALZip (https://alzip.en.softonic.com/) to view the contents of the .egg file, which showed that the bluetooth/widcomm.py was in fact present in the .egg file.
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\X\Python3\lib\site-packages\pybluez-0.30-py3.10-win-amd64.egg\bluetooth\widcomm.py'
had an issue with the name of the pybluez-0.30-py3.10-win-amd64.egg file so I solved it by Extracting the .egg file to a new folder, and renaming the folder to "pybluez-0.30-py3.10-win-amd64.egg" (yes the .egg should be part of the name as well)
These steps managed to solve the error and I was able to create an exe from my Python Script using pyinstaller. (pyinstaller scriptname.py)
I need uncompress .rar file in Google Colab with Python3. First I tried to do localy in MacOS.
I have installed Patoolib package:
pip install patool
and unrar to unzip .rar files
brew install unrar
Then, In my python script I do:
import patoolib
patoolib.extract_archive("data_2/Peliculas.rar", outdir="/data_2")
and I get the following error :
PatoolError: could not find an executable program to extract format rar; candidates are (rar,unrar,7z),
I need to configure Patool to use unrar but there is no documentation available. Somebody knows how to solve this error?
My issue was solved by simply adding my Winrar directory to my Path (in system environment variables). Made the horrible mistake of assuming it was set up by default (because why wouldn't it, it's already on the contextual menus right?), but that was not the case.
Hope this helps whoever reads this
I have been trying to install Scraperwiki module for Python. However, it generates the error:
""UserWarning: Local Scraperlibs requires pdftohtml, but pdftohtml was not found in the PATH. You probably need to install it".
I looked into poppler as they have pdftohtml file but I don't know how it works - whether there is a python library I need to install or a .exe file. And how do I go about installing it. Running on Windows.
Many Thanks
If you're not intending to use scraperwiki.pdftoxml(), then the warning doesn't apply. It doesn't stop you from installing the scraperwiki package, however.
Also, that function doesn't work on Windows at all as is; it uses NamedTemporaryFiles which behave differently on Windows to Linux.
If you do want to use that function, the simplest way to get an up-to-date version of pdftohtml on Windows is to download Calibre Portable. (The version on Sourceforge is older.)
Install it anywhere; you just need a few files from it. From where you installed it, from the folder containing calibre.exe, you need pdftohtml.exe into your working folder as well as, from the DLLs folder in the Calibre install, freetype.dll, jpeg.dll, libpng12.dll, zlib1.dll.
You'll also need code based on scraperwiki.pdftoxml() instead, like:
def pdftoxml(pdfdata, options):
"""converts pdf file to xml file"""
# lots of hacky Windows fixes c.f. original
with open('input.pdf', 'wb') as f:
f.write(pdfdata)
cmd = 'pdftohtml -xml -nodrm -zoom 1.5 -enc UTF-8 -noframes '
if options:
cmd += options
cmd += 'input.pdf output.xml'
cmd = cmd + " > NUL 2>&1"
os.system(cmd)
with open('output.xml', 'r') as f:
return f.read()
(I was trying to get this working for a user in Windows recently; I'll keep the gist containing this code updated.)
I am running a Python program on a Windows XP machine. When I run the program, I get the following error:
File "C:\Python27\lib\pysnmp\smi\builder.pyt, line 230, in loadModules...
pysnmp.smi.error.SmiError: MIB file "SNMPv2-MIB.py[co]" not found in search path
The file SNMPv2-MIB.py is currently located in C:\Python27\Lib\pysnmp\smi\mibs. Does anyone know how I can solve this?
if a mib is missing make sure you have performed a pip install pysnmp-mibs first if you used pip install pysnmp.
I just ran into the same issue. I filed a bug for it and included a patch:
https://sourceforge.net/tracker/?func=detail&aid=3204704&group_id=14735&atid=114735
As Sivakumar says, the reason it's failing is because pysnmp is looking for MIBs with a .pyc or .pyw extension. pysnmp gets these extensions from imp.get_suffixes(). Based on the way pysnmp deals with the extensions returned from this function, the .pyw entry will overwrite the .py entry. The fix I proposed will simply ignore the .pyw extension.
If you install the library from the .egg it should work fine because the .egg includes compiled (pyc) MIBs.
You are not able to load the MIB file.
Can you check :
>>> print builder.MibBuilder().getMibPath()
Usually this should be ok as the mib instances should be in
pysnmp/smi/mibs/instances
Code where error is raised in builder.py
if not self.__modSeen.has_key(modName):
raise error.SmiError(
'MIB file \"%s\" not found in search path' % (modName and modName + ".py[co]")
)
Usually this should get solved by calling setMibPath on the mibBuilder instance before calling loadModules.
Since the path you are getting
C:\Python27\lib\pysnmp\smi\mibs\instances,
C:\Python27\lib\pysnmp\smi\mibs,
C:\Python27\lib\pysnmp_mibs
Why don't you move the file to one of these directories?
The place where it is currently located
C:\Python27\Lib\pysnmp\smi\mibs
is not among the paths that you got via builder.MibBuilder().getMibPath()
I ran into the same issue (with pysnmp-4.2.5). I generated my own MIB python file using:
build-pysnmp-mib -o IF-MIB.py /usr/share/mibs/ietf/IF-MIB
on RHEL6 (build-pysnmp-mib does not work on RHEL5 as it requires libsmi version > 0.4.5 and RHEL5 just has this version while RHEL6 has 0.4.8).
Then I copied the generated file IF-MIB.py into the directory where the other python MIB files of pysnmp are located, (/.../site-packages/pysnmp/smi/mibs/)
Today i too face this same issue. The mibs path is correctly set. While running the pysnmp in debugging mode, i am able to found that it is expecting a SNMPv2-MIB.pyc or .pyw file.
Since i have unzipped the pysnmp from source and using it, the corresponding pyc file for the mib module is not available in that folder structure. I havent tried compiling the corresponding .py files available in the pysnmp-4.1.13a\pysnmp\smi\mibs\instances or pysnmp-4.1.13a\pysnmp\smi\mibs, instead i used the easyinstall script to download the pysnmp module.
With the egg file, now the issue is not coming.
Thanks
Sivakumar
This might be a weird requirement but it's what I've run into. I Googled but yield nothing.
I'm coding an application who's using a lot of constant attributes / values recorded in an XML file (they'll not change so a static file), things work fine until I generated an egg file for it.
When the logic reaches the XML accessing part, I got one complaint like this:
/home/Workspace/my_proj/dist/mps-1.2.0_M2-py2.6.egg/mps/par/client/syntax/syntax.xml
Actually I've bundled the XML file in the path above but seems Python doesn't know how to access it.
The code to access the XML is as...
file_handler = open(path_to_the_file)
lines = file_handler.read().splitlines()
Any idea?
egg files are zipfiles, so you must access "stuff" inside them with the zipfile module of the Python standard libraries, not with the built-in open function!
If you want to access the contents inside the .egg file you can simply rename it and change extension from .egg to .zip and than unzip it.
Which will create a folder and the contents will be same as they were when it was a .egg file
for example brewer2mpl-1.4.1-py3.6.egg
After Renaming brewer2mpl-1.4.1-py3.6.zip
Now if we open it, it'll get easily unzipped and the content will be put in a folder with same name in the same directory.
(tested on macOS Sierra)
The less command on *nix systems can peek inside zip files. Therefore less some.egg will list the contents of a .egg file too.
Just run unzip file.egg
You can install unzip on Debian/Ubuntu with
sudo apt install unzip
or on macOS by installing Homebrew then
brew install unzip
Access file from inside egg file
Yes, It is possible to read the files from inside egg file.
Egg file: mps-1.2.0_M2-py2.6.egg structure for module level example:
In driverfile.py:
import xml.etree.ElementTree
import mps.par.client as syntaxpath
import os
path = os.path.dirname(syntaxpath.__file__)
element = xml.etree.ElementTree.parse(path+'\\syntax\\syntax.xml').getroot()
print(element)
Read xml file from inside an eggfile:
PYTHONPATH=mps-1.2.0_M2-py2.6.egg python driverfile.py
i think by default eggs packing file under python won't add your xml inside to the pack