这是我第一次尝试使用pip-compile
frompip-tools
。
Django 项目的基本设置在main/settings/base.py
. 我将此部分添加为pip-tools
:
install_requires = [
'django-oscar>=3.0.2,<4.0.0',
'boto3==1.17.27',
'psycopg2-binary==2.8.6',
'pycountry==20.7.3',
]
pip-compile
当我尝试使用它时会爆炸。这怎么可能解决?
$ pip-compile main/settings/base.py
Traceback (most recent call last):
File "/var/work/django/oscar/lib/python3.8/site-packages/pip/_vendor/packaging/requirements.py", line 113, in __init__
req = REQUIREMENT.parseString(requirement_string)
File "/var/work/django/oscar/lib/python3.8/site-packages/pip/_vendor/pyparsing.py", line 1955, in parseString
raise exc
File "/var/work/django/oscar/lib/python3.8/site-packages/pip/_vendor/pyparsing.py", line 3250, in parseImpl
raise ParseException(instring, loc, self.errmsg, self)
pip._vendor.pyparsing.ParseException: Expected W:(abcd...), found '"' (at char 0), (line:1, col:1)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/var/work/django/oscar/lib/python3.8/site-packages/pip/_internal/req/constructors.py", line 342, in parse_req_from_line
req = Requirement(req_as_string)
File "/var/work/django/oscar/lib/python3.8/site-packages/pip/_vendor/packaging/requirements.py", line 115, in __init__
raise InvalidRequirement(
pip._vendor.packaging.requirements.InvalidRequirement: Parse error at "'"""'": Expected W:(abcd...)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/var/work/django/oscar/bin/pip-compile", line 8, in <module>
sys.exit(cli())
File "/var/work/django/oscar/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/var/work/django/oscar/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/var/work/django/oscar/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/var/work/django/oscar/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/var/work/django/oscar/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File "/var/work/django/oscar/lib/python3.8/site-packages/piptools/scripts/compile.py", line 369, in cli
constraints.extend(
File "/var/work/django/oscar/lib/python3.8/site-packages/piptools/_compat/pip_compat.py", line 26, in parse_requirements
yield install_req_from_parsed_requirement(parsed_req, isolated=isolated)
File "/var/work/django/oscar/lib/python3.8/site-packages/pip/_internal/req/constructors.py", line 458, in install_req_from_parsed_requirement
req = install_req_from_line(
File "/var/work/django/oscar/lib/python3.8/site-packages/pip/_internal/req/constructors.py", line 391, in install_req_from_line
parts = parse_req_from_line(name, line_source)
File "/var/work/django/oscar/lib/python3.8/site-packages/pip/_internal/req/constructors.py", line 357, in parse_req_from_line
raise InstallationError(msg)
pip._internal.exceptions.InstallationError: Invalid requirement: '"""' (from line 1 of main/settings/base.py)
更新 1:我在本节中遇到相同的错误:
install_requires = [
]
更新 2:我制作了一个文件,requirements.in
如下所示:
django-oscar>=3.0.2,<4.0.0
boto3==1.17.27
psycopg2-binary==2.8.6
pycountry==20.7.3
...并requirements.txt
正确生成:
$ pip-compile
# Long pause...
$ cat requirements.txt
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile
#
asgiref==3.3.1
# via django
babel==2.9.0
# via
# django-oscar
# django-phonenumber-field
boto3==1.17.27
# via -r requirements.in
botocore==1.20.45
# via
# boto3
# s3transfer
django-extra-views==0.13.0
# via django-oscar
django-haystack==3.0
# via django-oscar
django-oscar==3.0.2
# via -r requirements.in
django-phonenumber-field==3.0.1
# via django-oscar
django-tables2==2.3.4
# via django-oscar
django-treebeard==4.4
# via django-oscar
django-widget-tweaks==1.4.8
# via django-oscar
django==3.1.7
# via
# django-extra-views
# django-haystack
# django-oscar
# django-phonenumber-field
# django-tables2
# django-treebeard
factory-boy==2.12.0
# via django-oscar
faker==6.4.1
# via factory-boy
jmespath==0.10.0
# via
# boto3
# botocore
phonenumbers==8.12.18
# via django-oscar
pillow==8.1.0
# via django-oscar
psycopg2-binary==2.8.6
# via -r requirements.in
purl==1.5
# via django-oscar
pycountry==20.7.3
# via -r requirements.in
python-dateutil==2.8.1
# via
# botocore
# faker
pytz==2021.1
# via
# babel
# django
s3transfer==0.3.6
# via boto3
six==1.15.0
# via
# django-extra-views
# purl
# python-dateutil
sqlparse==0.4.1
# via django
text-unidecode==1.3
# via faker
urllib3==1.26.4
# via botocore
pip-tools
解析是否损坏setup.py
?