如何在Python2.7中安装pypi包?

2024-05-19 20:27:28 发布

您现在位置:Python中文网/ 问答频道 /正文

这个问题,当我尝试用pypi安装netstat包时

[opmeitle@localhost ~]$ sudo pip install netstat
[sudo] password for opmeitle: 

Downloading/unpacking netstat
  Running setup.py egg_info for package netstat

    file nester_g:.py (for module nester_g:) not found
Installing collected packages: netstat
  Running setup.py install for netstat
    file nester_g:.py (for module nester_g:) not found
    file nester_g:.py (for module nester_g:) not found
    warning: install_lib: 'build/lib' does not exist -- no Python modules to install


    file nester_g:.py (for module nester_g:) not found
    file nester_g:.py (for module nester_g:) not found
Successfully installed netstat
Cleaning up...

还有其他问题:如何在python2.7而不是3中安装软件包?


Tags: installpypypiforlibsetupsudonot
2条回答
  1. 您提到的包已损坏/不完整。从here下载源代码,您可以看到只有setup.py,没有其他源代码。除此之外,主页是一个断开的链接。

  2. 要为不同版本的python安装,请使用pip-2.7 install xxx。对于您安装的每个python版本,通常都有一个pip-x.y。

虽然Kugel's answer完全有效,但我也建议您避免在系统范围内安装,并使用virtualenv。 它将允许您为项目创建一个沙箱,并将其与其他项目隔离。

创建virtualenv时,可以指定要使用的Python解释器版本。例如,对于python2.7:

$ virtualenv path/to/project -p /usr/bin/python2.7

然后,pip install命令将自动安装python2.7的包。

相关问题 更多 >