pip install 安装Python库

本文详细介绍了如何使用pip进行Python包的安装、卸载及更新等操作,并提供了配置pip源的方法,帮助读者更好地管理和维护Python环境。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 在C:\Users\用户名\pip目录下,新建pip.ini

2.内容:

[global]
index-url = http://pypi.douban.com/simple
[install]
trusted-host=pypi.douban.com

3.命令行界面下:

pip install --proxy proxyIP:proxyPort [module name]

proxy可以不选

例:

pip install MySQL-python
pip install xxx:xxx:xxx:xx MySQL-python

以下来自:http://www.cnblogs.com/zengkefu/p/5624718.html

wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=834b2904f92d46aaa333267fb1c922bb" --no-check-certificate
[root@localhost ~]#tar -xvf pip-1.5.4.tar.gz
[root@localhost pip-1.5.4]#python setup.py install 

1. pip使用详解

1.1 pip安装包

[root@localhost ~]# pip install Django  
[root@localhost ~]# pip install MySQL-python 

 

 1.2 pip查看已安装的包

[root@localhost ~]# pip list
MySQL-python (1.2.5)            //MySQLDb 
pip (1.5.4)
redis (2.10.5)
setuptools (23.1.0)
wsgiref (0.1.2)

1.3 pip检查哪些包需要更新

[root@localhost ~]# pip list --outdated
pip (Current: 1.5.4 Latest: 8.1.2)

1.4 pip升级包

[root@localhost ~]# pip install --upgrade redis
Requirement already up-to-date: redis in /usr/local/lib/python2.7/site-packages
Cleaning up...

1.5 pip卸载包

2. pip参数解释

复制代码
[root@localhost ~]# pip --help

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
                              /root/.pip/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.
复制代码

 

 

复制代码
[root@localhost lib.linux-x86_64-2.7]# python
Python 2.7.9 (default, Mar 20 2016, 17:45:53) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-55)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "MySQLdb/__init__.py", line 19, in <module>
    import _mysql
ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory
复制代码

解决:

复制代码
ln -s /usr/local/mysql56/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18

如果是64系统则:
ln -s /usr/local/mysql56/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18

  vi /etc/ld.so.conf    //加入libmysqlclient.so.18 所在的目录:/usr/local/mysql56/lib/

  加入: /usr/lib/

  保存退出后执行/sbin/ldconfig生效



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值