The problem with Unrar in Python is that there is an error __python

Source: Internet
Author: User

First, my system and Python version information:

Win7, python2.7.12

I've been looking for two articles that I think are better:

The first article http://blog.csdn.NET/luoye7422/article/details/41873499, according to his method to really even the error is the same, but unfortunately, even if the C:\Program files\ The UnRAR.exe in the WinRAR directory is copied under the script folder or added to the environment variable to still report this error, so ... Can only give up, if a small partner in accordance with this method to be able to achieve the best. (In fact, the essence of this method is to encapsulate a popen function, that is, call the cmd Command window to extract, so interested students can directly to find Python call cmd method, and then write a decompression function on their own OK.) )

The second article http://blog.csdn.net/q1w2e3r4470/article/details/51859467, the operation is slightly more complicated than the first one (but it is only relative, in fact, I think the author is just not clear, I have collated it with the information I have consulted.

get to the point.

First step

Install the Unrar module pip install Unrar (don't explain how to use PIP)

Then try to enter the from Unrar import Rarfile and run in the IDE (I'm using pycharm), and it will display an error:

Lookuperror:couldn ' t find path to Unrar library.

It means we can't find the path to the Unrar library, we need to download this Unrar library, in fact it is UnRAR.dll this thing, download URL: Http://www.rarlab.com/rar/UnRARDLL.exe Or go to http://www.rarlab.com/rar_add.htm find UnRAR.dll download, in LUnix should need to compile their own.

Step Two:

The path to my computer after installation is C:\Program Files (x86) \unrardll,win7 32-bit friends can add it to the environment variable, 64-bit to set the X64 folder as the environment variable, Because the Unrar module recognizes files that are Unrar.dll and Unrar.lib, the UnRAR.dll and UnRAR.lib in the folder are renamed in lowercase.

All right, try the from Unrar import Rarfile and run, and it works. (In fact, I still have an error, I put the pycharm again after the boot will be good, may be pycharm update has a delay)

Step Three:

It's finally ready to unpack, and the order is simple.

Rarfile
file = rarfile. Rarfile (' file_name ')  #这里写入的是需要解压的文件, don't forget to add the path
file.extractall (' You_want_path ')  This is written in the folder you want to extract into.

Go to your designated folder and see if it's there.

If you want to know more about Unrar functions, you can go here: Https://github.com/matiasb/python-unrar

Check out the example below.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.