在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安装外部主机文件的更多相关文章

  1. pycharm中无法导入pip安装的包

    https://blog.csdn.net/mdxiaohu/article/details/82430060 2020.1.20 练习通过python操作数据库的时候需要导入一个包,因为看代码写的是 ...

  2. Python中,os.listdir遍历纯数字文件乱序如何解决

    Python中,os.listdir遍历纯数字文件乱序如何解决 日常跑深度学习视觉相关代码时,常常需要对数据集进行处理.许多图像文件名是利用纯数字递增的方式命名.通常所用的排序函数sort(),是按照 ...

  3. python中的BaseManager通信(一)文件三分

    可以在windows下单机运行 主部分(提供服务器) #mainfirst.py from multiprocessing.managers import BaseManager import Que ...

  4. python中使用multipart/form-data请求上传文件

    最近测试的接口是上传文件的接口,上传单个文件,我主要使用了2种方法~ 接口例如: URL: http://www.baidu.com/*** method:post 参数: { "salar ...

  5. python︱模块加载(pip安装)以及pycharm安装与报错解决方式

    每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- 准备放下R开始学python,真是痛苦,因为找 ...

  6. 【Python使用】使用pip安装卸载Python包(含离线安装Python包)未完成???

    pip 是 Python 包管理工具,该工具提供了对Python包的查找.下载.安装.卸载的功能.Python 2.7.9 + 或 Python 3.4+ 以上版本都自带 pip 工具. pip使用( ...

  7. Python版本切换和Pip安装

    Python版本切换 现在常用的linux系统中都会默认携带python运行环境,在ubuntu 16.04 和centos 7.3中携带有Python 2.7 和Python3.5两个版本, 默认使 ...

  8. python包管理之Pip安装及使用-1

    Python有两个著名的包管理工具easy_install.py和pip.在Python2.7的安装包中,easy_install.py是默认安装的,而pip需要我们手动安装. pip可以运行在Uni ...

  9. python包管理之Pip安装及使用

    Python有两个著名的包管理工具easy_install.py和pip.在Python2.7的安装包中,easy_install.py是默认安装的,而pip需要我们手动安装. pip可以运行在Uni ...

随机推荐

  1. ssh执行远程服务器脚本 提示php: command not found

    ssh执行远程服务器脚本 提示php: command not found 设置环境变量 一台机器作为管理机,来管理其他服务器,并通过key认证,免密码登陆的. 在管理机上通过ssh登陆到其他服务器来 ...

  2. c++ 一个cpp文件如何调用另一个cpp文件已经定义的类?我不想重复定义

    文件test1.cpp有类class A;文件test2.cpp有类class B.如在test2.cpp中想用A:#include "test1.cpp" 当然一般的做法是将类的 ...

  3. HDU 2435 There is a war

    There is a war Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ...

  4. Python3常用模块的安装

    1.mysql驱动:mysql-connector-python 1.安装 $ pip3 install mysql-connector-python --allow-external mysql-c ...

  5. 在LoadRunner向远程Linux/Unix执行命令行并收集性能数据

    前面介绍过在LoadRunner的Java协议实现“使用SSH连接Linux”,当然连接之后的故事由你主导. 今天要讲的,是一个非Java版本.是对“在LoadRunner中执行命令行程序之:pope ...

  6. nginx中access_log和nginx.conf中的log_format用法

    nginx服务器日志相关指令主要有两条: 一条是log_format,用来设置日志格式; 另外一条是access_log,用来指定日志文件的存放路径.格式和缓存大小 可以参加ngx_http_log_ ...

  7. Python 频繁读取Mysql相关问题

    1.需要频繁select大量数据,时间长.消耗内存大,如何解决mysql性能问题? 如果对返回的结果数量没有要求,可以控制返回的数量: cursor.fetchmany(size=1000) 这样是只 ...

  8. Codeforces 333E Summer Earnings ——Bitset

    [题目分析] 找一个边长最大的三元环. 把边排序,然后依次加入.加入(i,j)时,把i和j取一个交集,看看是否存在,存在就找到了最大的三元环. 输出即可,n^3/64水过. [代码] #include ...

  9. R语言入门--画图(一)--需要注意的地方

    一.注意‘\t’是‘\t’     不是‘/t’  写'/t'就错了   就不是换行符了 二.程序报错先检查有没有这个包

  10. bootstrap theme & template

    https://wrapbootstrap.com/ Unify http://wrapbootstrap.com/preview/WB0412697 https://htmlstream.com/p ...