Pipenv 无法使用 psycopg2-binary 锁定

Pipenv failing to lock with psycopg2-binary

我正在尝试为 Django 开发创建一个虚拟环境。我能够在另一个项目中成功安装 psycopg2-binary,但无法重现成功的安装。

环境:

  1. Python 3.8.1
  2. Pipenv版本2018.11.26

安装步骤:

mkdir test && cd test
pipenv install django psycopg2-binary==2.8.4

上 运行:

Installing psycopg2-binary==2.8.4…
Adding psycopg2-binary to Pipfile's [packages]…
Installation Succeeded
Pipfile.lock (24bc11) out of date, updating to (a6086c)…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
Locking Failed!
Traceback (most recent call last):
  File "c:/users/optiplex 3020/appdata/local/programs/python/python38-32/lib/site-packages/pipenv/resolver.py", line 126, in <module>
    main()
  File "c:/users/optiplex 3020/appdata/local/programs/python/python38-32/lib/site-packages/pipenv/resolver.py", line 118, in main
    _main(parsed.pre, parsed.clear, parsed.verbose, parsed.system,
  File "c:/users/optiplex 3020/appdata/local/programs/python/python38-32/lib/site-packages/pipenv/resolver.py", line 78, in _main
    results = resolve(
  File "c:/users/optiplex 3020/appdata/local/programs/python/python38-32/lib/site-packages/pipenv/resolver.py", line 61, in resolve
    return resolve_deps(
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\utils.py", line 718, in resolve_deps
    resolved_tree, hashes, markers_lookup, resolver = actually_resolve_deps(
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\utils.py", line 480, in actually_resolve_deps
    resolved_tree = resolver.resolve()
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\utils.py", line 385, in resolve
    results = self.resolver.resolve(max_rounds=environments.PIPENV_MAX_ROUNDS)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\piptools\resolver.py", line 102, in resolve
    has_changed, best_matches = self._resolve_one_round()
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\piptools\resolver.py", line 206, in _resolve_one_round
    for dep in self._iter_dependencies(best_match):
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\piptools\resolver.py", line 301, in _iter_dependencies
    dependencies = self.repository.get_dependencies(ireq)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\piptools\repositories\pypi.py", line 234, in get_dependencies
    legacy_results = self.get_legacy_dependencies(ireq)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\piptools\repositories\pypi.py", line 426, in get_legacy_dependencies
    results, ireq = self.resolve_reqs(download_dir, ireq, wheel_cache)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\piptools\repositories\pypi.py", line 297, in resolve_reqs
    results = resolver._resolve_one(reqset, ireq)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\notpip\_internal\resolve.py", line 260, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\notpip\_internal\resolve.py", line 211, in _get_abstract_dist_for
    abstract_dist = self.preparer.prepare_linked_requirement(
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\notpip\_internal\operations\prepare.py", line 294, in prepare_linked_requirement
    abstract_dist.prep_for_dist(finder, self.build_isolation)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\notpip\_internal\operations\prepare.py", line 127, in prep_for_dist
    self.req.run_egg_info()
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\notpip\_internal\req\req_install.py", line 470, in run_egg_info
    call_subprocess(
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\notpip\_internal\utils\misc.py", line 703, in call_subprocess
    raise InstallationError(
pipenv.patched.notpip._internal.exceptions.InstallationError: Command "python setup.py egg_info" failed with error code 1 in C:\Users\OPTIPL~1\AppData\Local\Temp\tmp3guv6vnobuild\psycopg2-binary\
File "c:/users/optiplex 3020/appdata/local/programs/python/python38-32/lib/site-packages/pipenv/resolver.py", line 126, in <module>
    main()
  File "c:/users/optiplex 3020/appdata/local/programs/python/python38-32/lib/site-packages/pipenv/resolver.py", line 118, in main
    _main(parsed.pre, parsed.clear, parsed.verbose, parsed.system,
  File "c:/users/optiplex 3020/appdata/local/programs/python/python38-32/lib/site-packages/pipenv/resolver.py", line 78, in _main
    results = resolve(
  File "c:/users/optiplex 3020/appdata/local/programs/python/python38-32/lib/site-packages/pipenv/resolver.py", line 61, in resolve
    return resolve_deps(
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\utils.py", line 718, in resolve_deps
    resolved_tree, hashes, markers_lookup, resolver = actually_resolve_deps(
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\utils.py", line 480, in actually_resolve_deps
    resolved_tree = resolver.resolve()
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\utils.py", line 385, in resolve
    results = self.resolver.resolve(max_rounds=environments.PIPENV_MAX_ROUNDS)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\piptools\resolver.py", line 102, in resolve
    has_changed, best_matches = self._resolve_one_round()
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\piptools\resolver.py", line 206, in _resolve_one_round
    for dep in self._iter_dependencies(best_match):
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\piptools\resolver.py", line 301, in _iter_dependencies
    dependencies = self.repository.get_dependencies(ireq)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\piptools\repositories\pypi.py", line 234, in get_dependencies
    legacy_results = self.get_legacy_dependencies(ireq)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\piptools\repositories\pypi.py", line 426, in get_legacy_dependencies
    results, ireq = self.resolve_reqs(download_dir, ireq, wheel_cache)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\piptools\repositories\pypi.py", line 297, in resolve_reqs
    results = resolver._resolve_one(reqset, ireq)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\notpip\_internal\resolve.py", line 260, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\notpip\_internal\resolve.py", line 211, in _get_abstract_dist_for
    abstract_dist = self.preparer.prepare_linked_requirement(
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\notpip\_internal\operations\prepare.py", line 294, in prepare_linked_requirement
    abstract_dist.prep_for_dist(finder, self.build_isolation)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\notpip\_internal\operations\prepare.py", line 127, in prep_for_dist
    self.req.run_egg_info()
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\notpip\_internal\req\req_install.py", line 470, in run_egg_info
    call_subprocess(
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\notpip\_internal\utils\misc.py", line 703, in call_subprocess
    raise InstallationError(
pipenv.patched.notpip._internal.exceptions.InstallationError: Command "python setup.py egg_info" failed with error code 1 in C:\Users\OPTIPL~1\AppData\Local\Temp\tmp3guv6vnobuild\psycopg2-binary\

尝试的解决方案:

正在删除 %LOCALDATA% 中的缓存\AppData\Local\pipenv\pipenv

pipenv lock --clear
pipenv lock -v

pipenv lock -v的输出:

Locking [dev-packages] dependencies…
Locking [packages] dependencies…
Locking Failed!
Using pip: -i https://pypi.org/simple
Using pip: -i https://pypi.org/simple
Using pip: -i https://pypi.org/simple

                          ROUND 1
Current constraints:
  django
  psycopg2-binary==2.8.4

Finding the best candidates:
  found candidate django==3.0.3 (constraint was <any>)
  found candidate psycopg2-binary==2.8.4 (constraint was ==2.8.4)

Finding secondary dependencies:
  django==3.0.3 not in cache, need to check index
  django==3.0.3             requires asgiref~=3.2, pytz, sqlparse>=0.2.2
  psycopg2-binary==2.8.4 not in cache, need to check index
Traceback (most recent call last):
  File "c:/users/optiplex 3020/appdata/local/programs/python/python38-32/lib/site-packages/pipenv/resolver.py", line 126, in <module>
    main()
  File "c:/users/optiplex 3020/appdata/local/programs/python/python38-32/lib/site-packages/pipenv/resolver.py", line 118, in main
    _main(parsed.pre, parsed.clear, parsed.verbose, parsed.system,
  File "c:/users/optiplex 3020/appdata/local/programs/python/python38-32/lib/site-packages/pipenv/resolver.py", line 78, in _main
    results = resolve(
  File "c:/users/optiplex 3020/appdata/local/programs/python/python38-32/lib/site-packages/pipenv/resolver.py", line 61, in resolve
    return resolve_deps(
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\utils.py", line 718, in resolve_deps
    resolved_tree, hashes, markers_lookup, resolver = actually_resolve_deps(
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\utils.py", line 480, in actually_resolve_deps
    resolved_tree = resolver.resolve()
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\utils.py", line 385, in resolve
    results = self.resolver.resolve(max_rounds=environments.PIPENV_MAX_ROUNDS)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\piptools\resolver.py", line 102, in resolve
    has_changed, best_matches = self._resolve_one_round()
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\piptools\resolver.py", line 206, in _resolve_one_round
    for dep in self._iter_dependencies(best_match):
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\piptools\resolver.py", line 301, in _iter_dependencies
    dependencies = self.repository.get_dependencies(ireq)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\piptools\repositories\pypi.py", line 234, in get_dependencies
    legacy_results = self.get_legacy_dependencies(ireq)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\piptools\repositories\pypi.py", line 426, in get_legacy_dependencies
    results, ireq = self.resolve_reqs(download_dir, ireq, wheel_cache)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\piptools\repositories\pypi.py", line 297, in resolve_reqs
    results = resolver._resolve_one(reqset, ireq)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\notpip\_internal\resolve.py", line 260, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\notpip\_internal\resolve.py", line 211, in _get_abstract_dist_for
    abstract_dist = self.preparer.prepare_linked_requirement(
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\notpip\_internal\operations\prepare.py", line 294, in prepare_linked_requirement
    abstract_dist.prep_for_dist(finder, self.build_isolation)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\notpip\_internal\operations\prepare.py", line 127, in prep_for_dist
    self.req.run_egg_info()
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\notpip\_internal\req\req_install.py", line 470, in run_egg_info
    call_subprocess(
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\notpip\_internal\utils\misc.py", line 703, in call_subprocess
    raise InstallationError(
pipenv.patched.notpip._internal.exceptions.InstallationError: Command "python setup.py egg_info" failed with error code 1 in C:\Users\OPTIPL~1\AppData\Local\Temp\tmpzbo1k1mpbuild\psycopg2-binary\
Using pip: -i https://pypi.org/simple
Using pip: -i https://pypi.org/simple

                          ROUND 1
Current constraints:
  django
  psycopg2-binary==2.8.4

Finding the best candidates:
  found candidate django==3.0.3 (constraint was <any>)
  found candidate psycopg2-binary==2.8.4 (constraint was ==2.8.4)

Finding secondary dependencies:
  django==3.0.3 not in cache, need to check index
  django==3.0.3             requires asgiref~=3.2, pytz, sqlparse>=0.2.2
  psycopg2-binary==2.8.4 not in cache, need to check index
Traceback (most recent call last):
  File "c:/users/optiplex 3020/appdata/local/programs/python/python38-32/lib/site-packages/pipenv/resolver.py", line 126, in <module>
    main()
  File "c:/users/optiplex 3020/appdata/local/programs/python/python38-32/lib/site-packages/pipenv/resolver.py", line 118, in main
    _main(parsed.pre, parsed.clear, parsed.verbose, parsed.system,
  File "c:/users/optiplex 3020/appdata/local/programs/python/python38-32/lib/site-packages/pipenv/resolver.py", line 78, in _main
    results = resolve(
  File "c:/users/optiplex 3020/appdata/local/programs/python/python38-32/lib/site-packages/pipenv/resolver.py", line 61, in resolve
    return resolve_deps(
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\utils.py", line 718, in resolve_deps
    resolved_tree, hashes, markers_lookup, resolver = actually_resolve_deps(
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\utils.py", line 480, in actually_resolve_deps
    resolved_tree = resolver.resolve()
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\utils.py", line 385, in resolve
    results = self.resolver.resolve(max_rounds=environments.PIPENV_MAX_ROUNDS)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\piptools\resolver.py", line 102, in resolve
    has_changed, best_matches = self._resolve_one_round()
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\piptools\resolver.py", line 206, in _resolve_one_round
    for dep in self._iter_dependencies(best_match):
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\piptools\resolver.py", line 301, in _iter_dependencies
    dependencies = self.repository.get_dependencies(ireq)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\piptools\repositories\pypi.py", line 234, in get_dependencies
    legacy_results = self.get_legacy_dependencies(ireq)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\piptools\repositories\pypi.py", line 426, in get_legacy_dependencies
    results, ireq = self.resolve_reqs(download_dir, ireq, wheel_cache)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\piptools\repositories\pypi.py", line 297, in resolve_reqs
    results = resolver._resolve_one(reqset, ireq)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\notpip\_internal\resolve.py", line 260, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\notpip\_internal\resolve.py", line 211, in _get_abstract_dist_for
    abstract_dist = self.preparer.prepare_linked_requirement(
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\notpip\_internal\operations\prepare.py", line 294, in prepare_linked_requirement
    abstract_dist.prep_for_dist(finder, self.build_isolation)
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\notpip\_internal\operations\prepare.py", line 127, in prep_for_dist
    self.req.run_egg_info()
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\notpip\_internal\req\req_install.py", line 470, in run_egg_info
    call_subprocess(
  File "c:\users\optiplex 3020\appdata\local\programs\python\python38-32\lib\site-packages\pipenv\patched\notpip\_internal\utils\misc.py", line 703, in call_subprocess
    raise InstallationError(
pipenv.patched.notpip._internal.exceptions.InstallationError: Command "python setup.py egg_info" failed with error code 1 in C:\Users\OPTIPL~1\AppData\Local\Temp\tmpzbo1k1mpbuild\psycopg2-binary\

有没有人遇到过类似的问题?我倾向于它是我如何尝试解决 pipenv 锁定的问题,因为我昨天没有遇到这个问题。

我使用这个线程解决了这个问题:https://github.com/pypa/pipenv/issues/3468

普遍认为 pipenv 不支持 3.8.1,我已经降级到 3.7.6 并将使用它直到提供支持。

在尝试安装之前先安装 postgresql 和 postgresql-contrib psycopg2-binary/psycopg2 解决了我的问题。值得一试。

sudo apt install postgresql postgresql-contrib