Solve the problem of prompt couldn’t find path to unrear library after installing unrear in Python

When we write Python scripts, since we use the Unrar library to extract RAR files, we always add:

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.
1. Go to the RARLab official download library files,, 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:, 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 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/ 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.

Read More: