2017-10-28 53 views
1

我使用pip freeze来取出我的virtualenv的每个依赖项,以便在其他位置使用此环境,以便像下面那样获取requirements.txt。为什么pip冻结生成package_name = 0.0.0

certifi==2017.7.27.1 
chardet==3.0.4 
get==0.0.0 
gevent==1.2.2 
greenlet==0.4.12 
idna==2.6 
numpy==1.13.3 
pandas==0.20.3 
post==0.0.0 
psycopg2==2.7.3.1 
public==0.0.0 
python-dateutil==2.6.1 
pytz==2017.2 
query-string==0.0.0 
request==0.0.0 
requests==2.18.4 
setupfiles==0.0.50 
six==1.11.0 
sqlalchemy==1.1.14 
urllib3==1.22 

我以前在其他电脑这个要求,但每当我试图运行PIP安装-r requirements.txt我有类似下面的错误。

$ pip install -r requirements.txt 
Requirement already satisfied: certifi==2017.7.27.1 in d:\workspace\juice-project\venv\lib\site-packages (from -r requirements.txt (line 1)) 
Requirement already satisfied: chardet==3.0.4 in d:\workspace\juice-project\venv\lib\site-packages (from -r requirements.txt (line 2)) 
Collecting get==0.0.0 (from -r requirements.txt (line 3)) 
    Using cached get-0.0.0.tar.gz 
    Complete output from command python setup.py egg_info: 
    Traceback (most recent call last): 
     File "<string>", line 1, in <module> 
     File "d:\workspace\juice-project\venv\lib\tokenize.py", line 452, in open 
     buffer = _builtin_open(filename, 'rb') 
    PermissionError: [Errno 13] Permission denied: 'C:\\Users\\verys\\AppData\\Local\\Temp\\pip-build-1cd8yl0b\\get\\setup.py' 

    ---------------------------------------- 
Command "python setup.py egg_info" failed with error code 1 in C:\Users\verys\AppData\Local\Temp\pip-build-1cd8yl0b\get\ 

我以为是窗户使用者的特权造成的,所以我花了很多时间来解决这个问题。我因为这个bug而非常恼火。你能解释为什么这些未使用的东西会产生,为什么这个错误可能是这样的?

+0

除了答案之外,还有一个问题:你真的安装了吗?你真的使用这些'get' /'request' /'setupfiles'吗?或者您是否尝试安装'requests',但错误输入?然后将您的计算机视为可能被黑客入侵并感染。我很难破译这些库,并且可能是作者故意做的,以隐藏恶意代码。阅读关于如何执行此类攻击的信息:https://nakedsecurity.sophos.com/2017/09/19/pypi-python-repository-hit-by-typosquatting-sneak-attack/ –

+0

@SergeyVasilyev我在我的原始virtualenv,并没有关于这个问题。但我在我公司的代理后面运行了这个环境。删除每行以0.0.0结尾的行后,我一直使用这个要求。 – verystrongjoe

+0

这里的区别在于:'request'没问题,'request'不是。前者是一个众所周知的库,后者可能是一个恶意软件包(由于其内部的秘密程度以及通过'setup.py'安装时执行多少额外* bash *逻辑)。仅仅输入一次就可以让后者及其依赖项进入你的虚拟世界。 –

回答

2

因为这些库 - get,request(同一作者) - 写入不正确。这不是你的问题,它是他们的问题。你无法从你身边解决这个问题。

看看他们setup.py

kwargs = dict() 

# known-issues: 
# pip running `python setup.py egg_info` before installation: 
# 1) pip checks metadata name pip/req/req_install.py:run_egg_info() 
# 2) pip attempts to discover all of the dependencies before installation 
name = os.path.basename(os.getcwd()).split(".")[0].lower() 

path = os.path.join(os.getcwd(), "requirements.txt") 
if os.path.exists(path) and os.path.isfile(path): 
    kwargs["install_requires"] = open(path).read().splitlines() 

setup(name=name, **kwargs) 

它不包含version=... kwarg。可悲的是,这个库将是总是版本0.0.0,这是setupfiles自制库(见here)的默认值。

PS:你真的想使用这种质量的图书馆吗?为什么不把这个few lines复制到你的代码?这不是nodejs世界,在这里可以使用像这样的纳米模块。


UPD:我刚刚注意到setup()不是来自setuptools,但是从setupfiles,也是同一作者,并宣布猜测键的值。所以,也许它应该工作。但由于安装约定的这种非标准用法而中断。

我不会说这是一种最好甚至是好的做法,以这种方式取代setuptools。而且它也不安全 - 恶意的库作者可以在工作站/服务器上注入任何可以执行的代码。特别是that hacky

尽管如此,在这个例子中它需要一个version=...参数,这些参数在这些库中是缺少的。