您的位置:首页 > 编程语言 > Python开发

python的几种常用安装包的方式

2017-06-15 22:51 357 查看

使用自带的pip

打开windows命令行,不需要输入“python”或输入”python3”,而是直接输入以下指令。我们默认系统环境变量已经按照安装位置设置好

一般安装之后默认是已经安装好了pip,我们可以直接使用:

对于python2:

pip install xxx


对于python3:

pip3 install xxx


要删除安装好的包,直接:

pip uninstall xxx  #python2
pip3 install xxx  #python3


如果发现在cmd中输入pip不能识别,并且系统环境变量设置没有问题,我们应该视为python没有安装pip工具,我们需要自行安装。

安装方法:

1、下载pip安装包



这里我们选择压缩包,解压之后里面会有一个setup.py,执行:

python setup.py install


2、添加环境变量

我的电脑是:

C:\Python27\Scripts


可以根据上一步骤安装成功的提示可以看到pip.exe安装到哪里了。

这样我们在cmd中输入pip出现以下:

>pip

Usage:
pip <command> [options]

Commands:
install                     Install packages.
download                    Download packages.
uninstall                   Uninstall packages.
freeze                      Output installed packages in requirements format.
list                        List installed packages.
show                        Show information about installed packages.
check                       Verify installed packages have compatible dependencies.
search                      Search PyPI for packages.
wheel                       Build wheels from your requirements.
hash                        Compute hashes of package archives.
completion                  A helper command used for command completion.
help                        Show help for commands.

General Options:
-h, --help                  Show help.
--isolated                  Run pip in an isolated mode, ignoring
environment variables and user configuration.
-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. Option is additive, and can be
used up to 3 times (corresponding to WARNING,
ERROR, and CRITICAL logging levels).
--log <path>                Path to a verbose appending log.
--proxy <proxy>             Specify a proxy in the form
[user:passwd@]proxy.server:port.
--retries <retries>         Maximum number of retries each connection should
attempt (default 5 times).
--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, (a)bort.
--trusted-host <hostname>   Mark this host as trusted, even though it does
not have valid or any HTTPS.
--cert <path>               Path to alternate CA bundle.
--client-cert <path>        Path to SSL client certificate, a single file
containing the private key and the certificate
in PEM format.
--cache-dir <dir>           Store the cache data in <dir>.
--no-cache-dir              Disable the cache.
--disable-pip-version-check
Don't periodically check PyPI to determine
whether a new version of pip is available for
download. Implied with --no-index.


证明安装成功。

easy_install

在命令行窗口中输入:

>easy_install
error:No urls,filenames,or requirements specified(see --help)


这证明已经安装好了easy_install工具。

其实上面的pip安装我们可以直接使用:

easy_install pip


从上面我们可以发现只要: easy_install +包名 即可。

有时可能会找不到匹配导致安装失败,需要尝试其他办法。

利用wheel文件

4000
首先我们需要安装wheel包:

pip install wheel


之后从网上下载要安装的包的wheel文件,例如我们要安装numpy包,我们从官网上下载.whl文件,要根据自己电脑的位数和安装的python版本来合理选择whl文件。



然后在命令行中切换到你下载保存的目录(使用cd指令),执行:

>pip install numpy-1.13.0-cp27-none-win_amd64.whl


等待安装成功即可。

end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python windows