Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何判断是否安装了Python setuptools?_Python_Pip_Setuptools - Fatal编程技术网

如何判断是否安装了Python setuptools?

如何判断是否安装了Python setuptools?,python,pip,setuptools,Python,Pip,Setuptools,我正在编写一个快速的shell脚本,使我们的一些开发人员能够更轻松地运行Fabric。(我也是Python新手。)安装Fabric的一部分是安装pip,安装pip的一部分是安装setuptools 是否有任何简单的方法可以检测是否已安装setuptools?我希望能够多次运行脚本,并跳过已经完成的任何操作。现在,如果连续运行两次ez_setup.py,第二次将失败 我的一个想法是在/scripts文件夹下查找easy_install脚本。我可以使用sys.executable猜测Python根目

我正在编写一个快速的shell脚本,使我们的一些开发人员能够更轻松地运行Fabric。(我也是Python新手。)安装Fabric的一部分是安装pip,安装pip的一部分是安装setuptools

是否有任何简单的方法可以检测是否已安装setuptools?我希望能够多次运行脚本,并跳过已经完成的任何操作。现在,如果连续运行两次ez_setup.py,第二次将失败


我的一个想法是在/scripts文件夹下查找easy_install脚本。我可以使用sys.executable猜测Python根目录,然后交换可执行文件名称本身。但我正在寻找更优雅一点的东西(也许是跨操作系统友好的)。有什么建议吗?

这不是很好,但会有用的

一个简单的python脚本可以完成检查

import sys
try:
    import setuptools
except ImportError:
    sys.exit(1)
else:
    sys.exit(0)


然后只需在调用脚本中检查它的退出代码即可

您可以通过运行以下命令行命令来检查easy_install和setuptools:

which easy_install
#finds the path to easy_install if it exists

less path/to/easy_install
#where path/to/easy_install is the output from the above command
#this outputs your easy_install script which will mention the version of setuptools
如果安装了easy_install/setuptools捆绑包,则上面第二个命令的输出可能会如下所示:

#EASY-INSTALL-ENTRY-SCRIPT: 'setuptools==0.6c11','console_scripts','easy_install'
尝试使用此命令

$ pip list
它返回
pip
setuptools
的版本。否则就试试看

$ pip install pil
$ which easy_install
如果这也不起作用,那么尝试使用

$ pip install pil
$ which easy_install

只需在空闲状态下运行以下代码:

import easy_install
如果它只是转到下一行,我想它已经安装好了。 如果它说:

Error: invalid syntax
那么它可能没有安装。 我知道这一点,因为我用它测试了皮普。
另外,只需检查导入pip,查看pip是否已预装。:)

它预装了Python的新版本

pip3 list

足以识别它是为我安装的

如果已安装,则将显示setuptools的版本


$python-c“导入系统;导入setuptools;打印(setuptools.version.\uuuuu version.\uuuuuu)”
取决于安装的python版本。您可以尝试
“pip列表”
“pip3列表”
并检查安装的安装工具和版本。

尝试导入easy\u install,如果它以您的方式抛出错误-它不在那里:)
pip列表
有效吗?在我的系统中,它发出一个未找到的命令错误。还可以查看“编辑帮助”中的标记语法,查看哪些选项可用于编辑。似乎我正在运行一个较旧的pip<代码>pip列表在pip 1.3中提供。是的,它起作用了。作为一个可安装的软件包,您可能想知道virtualenv中的setuptools版本。从源代码安装时,我没有预先安装