SoFunction
Updated on 2024-11-14

python install move copy third-party library operations

I. Introduction

Third party libraries are often used during development with python. Therefore it involves how to install, copy and move.

II. Installation

Installation of third-party libraries

1. python comes with a package manager: use the pip command to install it automatically. For example: pip install xlwings

2、Source code installation: in thepypiDownloaded tar, zip package to install locally.

2.1, pip installation method details

In the windows environment first open the cmd command window

Go to the Scripts directory in the python installation path.

Execute pip install library name

2.2. Source code installation

Download the library file zip and unzip it.

When you enter the extracted folder in a cmd command window, you'll usually see a file named

Execute the install command: python install

Third-party package installation path

Installation path of third-party libraries:\Python37\Lib\site-packages

IV. Third-party package copying and movement

Ideal for copying packages from one computer that has the package installed to another computer that does not have the package installed in the absence of an internet connection.

1. Go to the folder in the path where the third-party library is installed. \site-packages

2, find the package you need to copy can be. Note that a library package has two files, to be copied at the same time.

3. Move the package to \site-packages on another computer and paste it to use it.

Additional knowledge:Copying, deleting, and moving files and directories in python using shutil.

WARNING: Even the higher level file copy functions ((), shutil.copy2() ) cannot copy the metadata of all files. On POSIX platforms, this means that file owners and user groups are lost, as are ACLs. On Mac OS, since the resource fork and other metadata are not used, this means that resources are lost and file types and creator IDs are not maintained. On Windows, file owners, ACLs and alternate data streams are not copied.

Folder and file copying

(fsrc, fdst[, length])

Copies the contents of the file-like object fsrc to the file-like object fdst. The optional integer argument, length, specifies the buffer size. Specifically, a negative value of length prevents the copy operation from chunking the source data. By default, data is chunked into chunks to avoid uncontrollable memory consumption. Note: If the current file position of the fsrc object is not 0, only the contents from the current file position to the end of the file are copied.

(src, dst)

Copies the contents of the file src (without element data) into the file dst. dst must be a complete destination file. To copy a file to a destination folder, see (). src and dst cannot be the same file, or an error will be reported. The target file location must be writable, otherwise it will trigger aIOError. If dst already exists, it is overwritten. In particular, character devices, block devices, and pipes cannot be copied using this method. Use strings to specify the src and dst paths.

(src, dst)

Copy the file permission bits of src to dst. The contents of the file, its owners, and user groups are not affected. Use strings to specify the src and dst paths.

(src, dst)

Copies the file permission bits, last access time, last modification time, and **identification flags ** of the file src to dst. The contents of the file, its owners, and user groups are not affected. Use strings to specify the src and dst paths.

(src, dst)

Copies the file src to a dst file or folder. If dst is a folder, a file is created or overwritten in the folder with the same name as src. File permission bits are copied. Use strings to specify the src and dst paths.

shutil.copy2(src, dst)

Similar to (), but in addition copies the metadata of the file at the same time. In fact, this method is a combination of () and (). This method is the Unix equivalent of ` cp -p `.

shutil.ignore_patterns(*patterns)

This factory function creates a function that can be called with the value of the **ignore parameter** of () to skip correctly matching files and folders. For more information, see Leaving below.

(src, dst, symlinks=False, ignore=None)

Recursively copies the entire src folder. The destination folder is named dst and cannot already exist; the method automatically creates the dst root folder. Folder permissions and time are copied via (), individual files are copied via shutil.copy2(). If ` symlinks ` is true, symbolic links in the source folder will be preserved, but the metadata of the original links will not be copied. If false or omitted, the contents and metadata of the files pointed to by the links are copied to the new folder tree. If ignore is specified, it must be callable and be given as an argument to (). The arguments include the folder locally and return the contents of the folder via (). Since () copies recursively, ignore is called on each subfolder as it is copied. The callable must return a subset of the items in the current folder and a subset of the files in the folder. a subset of the items in the second argument); these folders and files are ignored during copying. A callable can be created using shutil.ignore_patterns().

If an accident occurs, () returns the cause of the error.

Moving and deleting

(path[, ignore_errors[, onerror]])

Delete the entire directory tree; path must point to a folder, but cannot be a symbolic link to a folder. If the value ` ignore_errors ` is true, messages about failed deletions will be ignored. If false or omitted, the errors are handled by the handler specified by onerror; if onerror is omitted, an exception is raised.

If onerror is specified, it must be a callable with three arguments: function, path and excinfo. The first argument is ` function `, which is used to raise the exception; the function can be (), (), (), (), (). The second argument, path, is the path passed to the first argument. The third argument, excinfo, is the exception information returned by sys.exc_info(). Exceptions raised by onerror are not caught.

(src, dst)

Move a file or folder from src to dst If dst already exists and is a folder, src will be moved into dst. If dst exists but is not a folder, dst may be overwritten depending on the semantics of (). If dst is on the same filesystem as src, then () is used. If not, shutil.copy2() will be used to copy src to dst and delete it.

This exception pools file operations when raise abnormalities。 for example (), the exception argument is a list of 3-tuples (srcname, dstname, exception).

Above this python install mobile copy third-party library operation is all that I have shared with you, I hope to give you a reference, and I hope you will support me more.