SoFunction
Updated on 2024-11-13

Python pip install non-PyPI official third-party libraries method

There are three ways to install non-self contained python modules in python.

1.easy_install

3. Download the compressed file (.zip, .tar, .). Unzip it, go to the extracted directory and execute the python install command.

This article focuses on a situation that may be encountered during pip installation, and the solution.

Suppose I want to install the pylint module, which does not come with python and can't be imported with import, so I need to install it additionally.

Copy Code The code is as follows.

>>> import pylint 
Traceback (most recent call last): 
  File "<stdin>", line 1, in <module> 
ImportError: No module named pylint 

[Phenomenon]

Executing the pip install <modulename> command reports the following error.

Copy Code The code is as follows.

D:\>pip install pylint --allow-external pylint 
Downloading/unpacking pylint 
Requirement already satisfied (use --upgrade to upgrade): six in c:\python27\lib\site-packages\six-1 
.8.0-py2. (from pylint) 
Downloading/unpacking astroid>=1.3.6 (from pylint) 
  Real name of requirement astroid is astroid 
  Could not find any downloads that satisfy the requirement astroid>=1.3.6 (from pylint) 
  Some insecure and unverifiable files were ignored (use --allow-unverified astroid to allow). 
Cleaning up... 
No distributions at all found for astroid>=1.3.6 (from pylint) 
Storing debug log for failure in C:\Users\aaa\pip\ 

[Analysis]

To install a new module in Perl, you can generally use the PPM graphical tool, you can also use CPAN to install, for example: cpan>install Test::Class, very convenient, will not run into this situation, this situation is mainly due to the pip version of the problem: pip the latest version (1.5 or more versions), for security reasons
Consider that pip does not allow the installation of non-PyPI URLs because that installation file actually comes from ,thus causing the error above!

NOTE:

1. Can be found in the officialchangelogView the changed information inside
2. You can use pip --version to view pip version information.

Copy Code The code is as follows.

C:\>pip --version 
pip 1.5.6 from C:\Python27\lib\site-packages (python 2.7) 

[Approach]

In response to the above, since the problem is due to the pip version, you can change to a lower pip version
Method 1: Use pip version 1.4, and then run pip install pylint to install
Method 2: Execute the command with --allow-all-external, --allow-unverified and the dependent package version (astroid==1.3.6).

Copy Code The code is as follows.

pip install pylint --allow-all-external pylint astroid==1.3.6 --allow-unverified pylint

NOTE:
1. --allow-all-external # Allow all external address labels, only with this label pip can download the external address module
2. --allow-unverified # pip has no way to check the validity of external modules, so it must be tagged as well.
3. astroid==1.3.6 # Dependencies must be added and given a version number for pip to download from the list.

Method 3: In the current directory, add the following.

Copy Code The code is as follows.

#  
--allow-all-external pylint 
--allow-unverified pylint 
pylint 
--allow-all-external astroid==1.3.6 

Then run: pip install -r
[Conclusion]
1. pip is not friendly enough and not easy to use, far from the PPM in Perl, looking forward to have such a tool in Python.
2. If you encounter this kind of error, resulting in the failure to install the module: Download the zip package and install it directly. >>>Download package address<<<
3. Execute the pip -h command to view the updated pip-related help information.

Copy Code The code is as follows.

Usage:    
  pip <command> [options] 
 
Commands: 
  install                     Install packages. 
  uninstall                   Uninstall packages. 
  freeze                      Output installed packages in requirements format. 
  list                        List installed packages. 
  show                        Show information about installed packages. 
  search                      Search PyPI for packages. 
  wheel                       Build wheels from your requirements. 
  zip                         DEPRECATED. Zip individual packages. 
  unzip                       DEPRECATED. Unzip individual packages. 
  bundle                      DEPRECATED. Create pybundles. 
  help                        Show help for commands. 
 
General Options: 
  -h, --help                  Show help. 
  -v, --verbose               Give more output. Option is additive, and can be used up to 3 times. 
  -V, --version               Show version and exit. 
  -q, --quiet                 Give less output. 
  --log-file <path>           Path to a verbose non-appending log, that only logs failures. This log is active by default at . 
  --log <path>                Path to a verbose appending log. This log is inactive by default. 
  --proxy <proxy>             Specify a proxy in the form [user:passwd@]:port. 
  --timeout <sec>             Set the socket timeout (default 15 seconds). 
  --exists-action <action>    Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup. 
  --cert <path>               Path to alternate CA bundle.