Python中怎样用pip安装外部主机文件
在python中安装非自带python模块。有三种方式:
- easy_install
- pip
- 下载压缩包(.zip, .tar, .tar.gz)后解压, 进入解压缩的文件夹后运行python setup.py install命令
本文主要针对pip安装时可能会碰到的一种情况,及解决的方法:
假如我要安装pylint模块。该模块非python自带模块。用import肯定不能导入,须要额外安装
>>> import pylint
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pylint
【现象】
运行pip install <modulename>命令,报错例如以下:
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.7.egg (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\pip.log
【分析】
在Perl中安装新模块。一般能够用PPM图形化工具,也能够用CPAN来安装,比方说: cpan>install Test::Class, 很方便。不会碰到这样的情况,这样的情况主要是由于pip版本号问题: pip最新的版本号(1.5以上的版本号), 出于安全的考
虑,pip不同意安装非PyPI的URL,由于该安装文件实际上来自pylint.org,因而导致上面的错误!
NOTE:
1. 能够在官方changelog里面查看更改的信息
2. 能够用pip --version来查看pip的版本号信息
C:\>pip --version
pip 1.5.6 from C:\Python27\lib\site-packages (python 2.7)
【办法】
针对上面的情况,既然这个问题是由于pip版本号的原因,能够改用pip低一点的版本号
方法一: 用pip 1.4版本号,再运行pip install pylint命令来安装
方法二: 运行命令时。加上--allow-all-external, --allow-unverified及依赖包版本号(astroid==1.3.6)
pip install pylint --allow-all-external pylint astroid==1.3.6 --allow-unverified pylint
NOTE:
1. --allow-all-external # 同意全部外部地址的标签。仅仅有打上该标签pip方可下载外部地址模块
2. --allow-unverified # pip没有办法校验外部模块的有效性,所以必须同一时候打上该标签
3. astroid==1.3.6 # 依赖包必需要加入上,并赋予其版本,pip方能从列表下载
方法三: 在当前文件夹下。新增requirements.txt,内容例如以下:
# requirements.txt
--allow-all-external pylint
--allow-unverified pylint
pylint
--allow-all-external astroid==1.3.6
再运行: pip install -r requirements.txt
【结论】
1. pip这个设计不够友好,使用也非常不方便。远不如Perl中的PPM,期待Python中也有这么个工具。
2. 假设碰到这样的错,导致不能安装模块的话: 直接下载压缩包安装好了。 >>>下载包地址<<<
3. 运行pip -h命令查看更新pip相关的帮助信息
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 pip.log.
--log <path> Path to a verbose appending log. This log is inactive by default.
--proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server: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.
Python中怎样用pip安装外部主机文件的更多相关文章
- pycharm中无法导入pip安装的包
https://blog.csdn.net/mdxiaohu/article/details/82430060 2020.1.20 练习通过python操作数据库的时候需要导入一个包,因为看代码写的是 ...
- Python中,os.listdir遍历纯数字文件乱序如何解决
Python中,os.listdir遍历纯数字文件乱序如何解决 日常跑深度学习视觉相关代码时,常常需要对数据集进行处理.许多图像文件名是利用纯数字递增的方式命名.通常所用的排序函数sort(),是按照 ...
- python中的BaseManager通信(一)文件三分
可以在windows下单机运行 主部分(提供服务器) #mainfirst.py from multiprocessing.managers import BaseManager import Que ...
- python中使用multipart/form-data请求上传文件
最近测试的接口是上传文件的接口,上传单个文件,我主要使用了2种方法~ 接口例如: URL: http://www.baidu.com/*** method:post 参数: { "salar ...
- python︱模块加载(pip安装)以及pycharm安装与报错解决方式
每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- 准备放下R开始学python,真是痛苦,因为找 ...
- 【Python使用】使用pip安装卸载Python包(含离线安装Python包)未完成???
pip 是 Python 包管理工具,该工具提供了对Python包的查找.下载.安装.卸载的功能.Python 2.7.9 + 或 Python 3.4+ 以上版本都自带 pip 工具. pip使用( ...
- Python版本切换和Pip安装
Python版本切换 现在常用的linux系统中都会默认携带python运行环境,在ubuntu 16.04 和centos 7.3中携带有Python 2.7 和Python3.5两个版本, 默认使 ...
- python包管理之Pip安装及使用-1
Python有两个著名的包管理工具easy_install.py和pip.在Python2.7的安装包中,easy_install.py是默认安装的,而pip需要我们手动安装. pip可以运行在Uni ...
- python包管理之Pip安装及使用
Python有两个著名的包管理工具easy_install.py和pip.在Python2.7的安装包中,easy_install.py是默认安装的,而pip需要我们手动安装. pip可以运行在Uni ...
随机推荐
- (转)iOS字体
一.iOS原生字体展示 在 label中选择字体的font,并把font由system改成custom后,就能在family中看到72种特殊字体.这些里面就有很炫的字体,但 是全部是只针对英文数字,对 ...
- Docker镜像分层技术
Docker镜像管理 1.镜像分层技术 2.创建镜像 3.下载镜像到主机 4.删除镜像 5.上传镜像到registry docker镜像: 早在集装箱没有出现的时候,码头上还有许多搬运的工人在搬运货物 ...
- C/C++ 程序中调用命令行命令并获取命令行输出结果
在 c/c++ 程序中,可以使用 system()函数运行命令行命令,但是只能得到该命令行的 int 型返回值,并不能获得显示结果.例如system(“ls”)只能得到0或非0,如果要获得ls的执行结 ...
- Vue && Angular 双向绑定检测不到对象属性的添加和删除
由于ES5的限制 Vue && Angular 双向绑定检测不到对象属性的添加和删除 还有数组增加索引.这些改变不会触发change事件.Vue是因为实例化的时候已经把各个属性都s ...
- Hubtown
Hubtown 时间限制: 10 Sec 内存限制: 256 MB 题目描述 Hubtown is a large Nordic city which is home to n citizens. ...
- *Codeforces961G. Partitions
$k \leq n \leq 100000$,求式子$Ans=\sum_{i=1}^n w_i\sum_{j=1}^n j\binom{n-1}{n-j} \{ ^{n-j}_{k-1} \}$. 题 ...
- Java面试题集(四)
二. Java Web基础部分 在js中如何创建一个对象? var p1={name:”tom”,”age”:12}; function Person(name,age){ this.name=nam ...
- msp430项目编程43
msp430综合项目---蓝牙控制直流电机调速系统43 1.电路工作原理 2.代码(显示部分) 3.代码(功能实现) 4.项目总结
- jQuery on() 和 live
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script sr ...
- Redis数据结构之链表
Redis使用的链表是双向无环链表,链表节点可用于保存各种不同类型的值. 一.链表结构定义1. 链表节点结构定义: 2. 链表结构定义: 示例: 二.链表在Redis中的用途1. 作为列表键的底层实现 ...