from unrar import rarfile
If you are using an IDE like PyCharm on Windows, it will prompt you to import packages, or you can manually search for third-party libraries in the project Settings and install them.
It is recommended to use the PIP install rarfile and PIP install unrar commands to install these libraries if it is a Linux command environment.
However, you will notice that after doing the above, the Python program does not decompress and it will say Couldn’t find path to Unrar Library… An error caused the program to interrupt.
At that time, I was puzzled. I installed the library, why can’t I find it?
After several checks, from the Python – Unrar open source project official website learned that Python under the Unrar also relies on the RAR official library.
So, the next two Windows and Linux systems to introduce the solution steps.
Win:
1. Go to the RARLab official download library files, http://www.rarlab.com/rar/UnRARDLL.exe, and installation;
2. It is best to choose the default path for installation, usually in the C: Program Files (x86)\ Unrardll \ directory;
3. Then the important step is to add the environment variable, this computer (my computer) right click, properties, find advanced system Settings, advanced TAB click environment variable, in the system variable (note not user variable) in the new, variable name input UNRAR_LIB_PATH, must be exactly the same, the value of the variable should pay special attention to! If you are a 64-bit system, type C:\Program Files (x86)\ Unrardll \x64\ Unrar64.dll, if you are a 32-bit system, type C:\Program Files (x86)\ Unrard.dll.
4. Once you are sure to save your environment variables, restart your PyCharm with the same code and run it again without any errors. At this point the dependent libraries have been added to the system environment.
Linux needs to manually compile and generate the SO file itself, which is a bit more cumbersome:
1. In the same way, the first to download the Source file, but it’s not like a Win for you packaging good, you need to download the Source code: http://www.rarlab.com/rar/unrarsrc-5.4.5.tar.gz, namely RARLab website to download the list of UnRAR Source, you can download the latest version;
Make install-lib will automatically compile the library files. After the compilation is complete, use the make install-lib command to generate the libunrar.so file (usually under /usr/lib).
3. Finally, you still need to set the environment variable of your Linux system, find the profile file in the /etc/profile directory, which you can edit directly using the Vim /etc/profile command (even more convenient with WinSCP), add export UNRAR_LIB_PATH=/usr/lib/libunrar.so at the end of the profile, don’t put the comma in it. Save the variable successfully and then use the source /etc/profile command to make the variable effective.
4. If you run the py file again, you won’t get an error, at least you won’t get a warning that you can’t find the unrar library.
Sudo apt-get install g++ : sudo apt-get install g++ : sudo apt-get install g++ : sudo apt-get install g++ : sudo apt-get install
In conclusion, the normal order of installation should be to install the dependent libraries, configure the environment variables, and then PIP install unrar or import unrar libraries in the IDE. However, you can only make up for the error, and the final effect is the same.
References:
https://github.com/matiasb/python-unrar/blob/master/README.md
http://stackoverflow.com/questions/31834502/couldnt-find-path-to-unrar-library-in-linux
http://blog.csdn.net/big_talent/article/details/52367184
Read More:
- Could’t find path to unrear Library
- Lookuperror: couldn’t find path to unrear library! two thousand and twenty
- LookupError: Couldn’t find path to unrar library.
- How to solve the problem of Cannot find module’npmlog’ when installing nodejs under Linux
- Error in installing Matplotlib Library: permissionerror: [errno 13] permission denied: ‘/ usr / local / lib / python3.6’
- Solve the problem of Python in Windows environment: Fatal error in launcher: Unable to create process using’”‘ in pip installation
- Solve the problem of unable to locate package python3.6 when upgrading from python3.5 to python3.6 in ubantu16.04
- Cannot find module ‘.. / lib / utils / unsupported. JS’ problem in installing node in centos7
- Arduino reports an error when writing a custom library file to solve the problem of not name of type, not declared in this scope
- Installing PyQt4 in Windows + Python 3.6
- Solve the problem of installing APK after Android studio compilation: error while installing apk
- Solve the problem of VC6.0 open crash and OpenGL glut32.lib library
- Prompt “libevent not found” when installing tmux
- Solution of OpenCV library import error in Python 3
- Solution to the problem of installing lxml in Pip
- About adding legacy to linker additional dependencies_ stdio_ definitions.lib Solve the problem of incomplete standard library files
- How to solve the problem of error reporting in the introduction of Python Django no module name ‘Django. Utils. Six’
- To solve the problem of loading rjava in installation of xlsx
- Configuration (9) to solve the problem of “setup tools PIP wheel failed with error code 1”, create virtual environments with Python of anaconda
- Installing sklearn (scikit learn) module related to Python machine learning in Windows