为什么pip freeze geneate package_name = 0.0.0

时间:2017-10-28 16:12:27

标签: pip

我使用pip freeze来取出virtualenv的所有依赖关系以在其他地方使用这个环境,这样我就得到了如下所示的requirements.txt。

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 install -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\

我认为这是由窗口用户的权限引起的,所以我花了很多时间用其他原因来解决这个问题。由于这个错误,我很生气。你能解释为什么这些未使用的东西会产生,为什么这个错误会像这样?

1 个答案:

答案 0 :(得分:2)

因为这些库 - getrequest(同一作者) - 写得不正确。这不是你的问题,而是他们的问题。你无法解决这个问题。

看看他们的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=...参数,这些参数在这些库中缺失。