在django项目中使用pipenv安装包时发生了错误。

huangapple go评论207阅读模式
英文:

An error occurred while installing a package using pipenv in the django project

问题

似乎 pipenv lock 本身没有生效。以下是错误信息。是否有解决方案?

错误:pip.subprocessor:[present-rich] 获取构建轮所需的依赖时返回了退出码 1
[ResolutionFailure]:   文件 "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/resolver.py",第 811 行,在 _main 中
[ResolutionFailure]:       resolve_packages(
[ResolutionFailure]:   文件 "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/resolver.py",第 759 行,在 resolve_packages 中
[ResolutionFailure]:       results, resolver = resolve(
[ResolutionFailure]:   文件 "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/resolver.py",第 738 行,在 resolve 中
[ResolutionFailure]:       return resolve_deps(
[ResolutionFailure]:   文件 "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/utils/resolver.py",第 1154 行,在 resolve_deps 中
[ResolutionFailure]:       results, hashes, markers_lookup, resolver, skipped = actually_resolve_deps(
[ResolutionFailure]:   文件 "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/utils/resolver.py",第 953 行,在 actually_resolve_deps 中
[ResolutionFailure]:       resolver.resolve()
[ResolutionFailure]:   文件 "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/utils/resolver.py",第 700 行,在 resolve 中
[ResolutionFailure]:       raise ResolutionFailure(message=str(e))
[pipenv.exceptions.ResolutionFailure]: 警告: 无法解析您的依赖项。您可能在子依赖项中存在版本不匹配。
  您可以使用 $ pipenv install --skip-lock 来绕过此机制,然后运行 $ pipenv graph 来检查情况。
  提示: 如果是预发行版本依赖关系,请尝试使用 $ pipenv lock --pre。
错误: 获取构建轮所需的依赖时返回了退出码 1

Traceback (most recent call last):
  文件 "/home/ubuntu/.local/bin/pipenv",第 8 行,在 <module> 中
    sys.exit(cli())
  文件 "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/vendor/click/core.py",第 1130 行,在 __call__ 中
    return self.main(*args, **kwargs)
  文件 "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/cli/options.py",第 58 行,在 main 中
    return super().main(*args, **kwargs, windows_expand_args=False)
  文件 "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/vendor/click/core.py",第 1055 行,在 main 中
    rv = self.invoke(ctx)
  文件 "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/vendor/click/core.py",第 1657 行,在 invoke 中
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  文件 "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/vendor/click/core.py",第 1404 行,在 invoke 中
    return ctx.invoke(self.callback, **ctx.params)
  文件 "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/vendor/click/core.py",第 760 行,在 invoke 中
    return __callback(*args, **kwargs)
  文件 "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/vendor/click/decorators.py",第 84 行,在 new_func 中
    return ctx.invoke(f, obj, *args, **kwargs)
  文件 "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/vendor/click/core.py",第 760 行,在 invoke 中
    return __callback(*args, **kwargs)
  文件 "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/vendor/click/decorators.py",第 26 行,在 new_func 中
    return f(get_current_context(), *args, **kwargs)
  文件 "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/cli/command.py",第 579 行,在 update 中
    do_update(
  文件 "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/routines/update.py",第 69 行,在 do_update 中
    do_lock(
  文件 "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/routines/lock.py",第 79 行,在 do_lock 中
    venv_resolve_deps(
  文件 "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/utils/resolver.py",第 1096 行,在 venv_resolve_deps 中
    c = resolve(cmd, st, project=project)
  文件 "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/utils/resolver.py",第 990 行,在 resolve 中
    raise RuntimeError("锁定 Pipfile.lock 失败!")
RuntimeError: 锁定 Pipfile.lock 失败!

以下是尝试使用已安装的 Pipfile 和 pipenv graph 的结果,但我不知道如何解决这个问题。无法锁定它。似乎是一个 wheel 或 uwsgi 的问题,但我不知道如何解决它。

Pipfile

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
django = "==4.2"
djangorestframework = "*"
django-cors-headers = "*"
pyjwt = "*"
djangorestframework-simplejwt = "*"
python-dotenv = "*"
pillow = "*"
wheel = "*"
boto3 = "*"
django-storages = "*"
mysqlclient = "*"
dj-rest-auth = "*"
django-allauth = "*"
uwsgi = "*"
setuptools = "*"
pip = "*"

[dev-packages]
black = "*"

[requires]
python_version = "3.10"

$ pipenv graph

"Pipfile" 28L, 444B 23,0-1 All
    - python-dateutil [required: >=2.1,<3.0.0, installed: 2.8.2]
      - six [required: >=1.5, installed: 1.16.0]
    - urllib3 [required: >=1.25.4,<1.27, installed: 1.26.16]
  - jmespath [required: >=0.7.1,<2.0.0, installed: 1.0.1]
  - s3transfer [required: >=0.6.0,<0.7.0, installed: 0.6.1]
    - botocore [required: >=1.12.

<details>
<summary>英文:</summary>

It seems that pipenv lock itself is not working. Below is the error content. Is there a solution?

ERROR:pip.subprocessor:[present-rich] Getting requirements to build wheel exited with 1
[ResolutionFailure]: File "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/resolver.py", line 811, in _main
[ResolutionFailure]: resolve_packages(
[ResolutionFailure]: File "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/resolver.py", line 759, in resolve_packages
[ResolutionFailure]: results, resolver = resolve(
[ResolutionFailure]: File "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/resolver.py", line 738, in resolve
[ResolutionFailure]: return resolve_deps(
[ResolutionFailure]: File "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/utils/resolver.py", line 1154, in resolve_deps
[ResolutionFailure]: results, hashes, markers_lookup, resolver, skipped = actually_resolve_deps(
[ResolutionFailure]: File "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/utils/resolver.py", line 953, in actually_resolve_deps
[ResolutionFailure]: resolver.resolve()
[ResolutionFailure]: File "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/utils/resolver.py", line 700, in resolve
[ResolutionFailure]: raise ResolutionFailure(message=str(e))
[pipenv.exceptions.ResolutionFailure]: Warning: Your dependencies could not be resolved. You likely have a mismatch in your sub-dependencies.
You can use $ pipenv install --skip-lock to bypass this mechanism, then run $ pipenv graph to inspect the situation.
Hint: try $ pipenv lock --pre if it is a pre-release dependency.
ERROR: Getting requirements to build wheel exited with 1

Traceback (most recent call last):
File "/home/ubuntu/.local/bin/pipenv", line 8, in <module>
sys.exit(cli())
File "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1130, in call
return self.main(*args, **kwargs)
File "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/cli/options.py", line 58, in main
return super().main(*args, **kwargs, windows_expand_args=False)
File "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/vendor/click/decorators.py", line 84, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/vendor/click/decorators.py", line 26, in new_func
return f(get_current_context(), *args, **kwargs)
File "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/cli/command.py", line 579, in update
do_update(
File "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/routines/update.py", line 69, in do_update
do_lock(
File "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/routines/lock.py", line 79, in do_lock
venv_resolve_deps(
File "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/utils/resolver.py", line 1096, in venv_resolve_deps
c = resolve(cmd, st, project=project)
File "/home/ubuntu/.local/lib/python3.10/site-packages/pipenv/utils/resolver.py", line 990, in resolve
raise RuntimeError("Failed to lock Pipfile.lock!")
RuntimeError: Failed to lock Pipfile.lock!

Below is the result of trying the installed Pipfile and pipenv graph, but I don&#39;t know how to solve the problem. It&#39;s impossible to lock it. It seems to be a wheel or uwsgi problem, but I don&#39;t know how to solve it.

Pipfile

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
django = "==4.2"
djangorestframework = ""
django-cors-headers = "
"
pyjwt = ""
djangorestframework-simplejwt = "
"
python-dotenv = ""
pillow = "
"
wheel = ""
boto3 = "
"
django-storages = ""
mysqlclient = "
"
dj-rest-auth = ""
django-allauth = "
"
uwsgi = ""
setuptools = "
"
pip = "*"

[dev-packages]
black = "*"

[requires]
python_version = "3.10"


$ pipenv graph

"Pipfile" 28L, 444B 23,0-1 All
- python-dateutil [required: >=2.1,<3.0.0, installed: 2.8.2]
- six [required: >=1.5, installed: 1.16.0]
- urllib3 [required: >=1.25.4,<1.27, installed: 1.26.16]

  • jmespath [required: >=0.7.1,<2.0.0, installed: 1.0.1]
  • s3transfer [required: >=0.6.0,<0.7.0, installed: 0.6.1]
    • botocore [required: >=1.12.36,<2.0a.0, installed: 1.29.146]
      • jmespath [required: >=0.7.1,<2.0.0, installed: 1.0.1]
      • python-dateutil [required: >=2.1,<3.0.0, installed: 2.8.2]
        • six [required: >=1.5, installed: 1.16.0]
      • urllib3 [required: >=1.25.4,<1.27, installed: 1.26.16]
        django-cors-headers==4.0.0
  • Django [required: >=3.2, installed: 4.2]
    • asgiref [required: >=3.6.0,<4, installed: 3.7.2]
      • typing-extensions [required: >=4, installed: 4.6.3]
    • sqlparse [required: >=0.3.1, installed: 0.4.4]
      django-storages==1.13.2
  • Django [required: >=3.2, installed: 4.2]
    • asgiref [required: >=3.6.0,<4, installed: 3.7.2]
      • typing-extensions [required: >=4, installed: 4.6.3]
    • sqlparse [required: >=0.3.1, installed: 0.4.4]
      djangorestframework-simplejwt==5.2.2
  • django [required: Any, installed: 4.2]
    • asgiref [required: >=3.6.0,<4, installed: 3.7.2]
      • typing-extensions [required: >=4, installed: 4.6.3]
    • sqlparse [required: >=0.3.1, installed: 0.4.4]
  • djangorestframework [required: Any, installed: 3.14.0]
    • django [required: >=3.0, installed: 4.2]
      • asgiref [required: >=3.6.0,<4, installed: 3.7.2]
        • typing-extensions [required: >=4, installed: 4.6.3]
      • sqlparse [required: >=0.3.1, installed: 0.4.4]
    • pytz [required: Any, installed: 2023.3]
  • pyjwt [required: >=1.7.1,<3, installed: 2.7.0]
    mysqlclient==2.1.1
    Pillow==9.5.0
    python-dotenv==1.0.0
    uWSGI==2.0.21

</details>


# 答案1
**得分**: 1

问题已经解决!这是由于本地(mac M1芯片)和分发环境之间的不同Python版本引起的问题。由于本地环境中使用了conda,并在版本3.9中创建了基本虚拟环境,因此基本虚拟环境会自动运行。

可能有人遇到了与我相同的问题,所以我在下面提供一个解决方案。

1. 在服务器环境中清除所有的Pipfile和Pipfile.lock,并重新安装包。
2. 使用`$pipenv --python 3.10`创建一个与部署环境匹配的虚拟环境,同时从本地环境中删除所有已创建的虚拟环境,包括conda。
3. 在本地环境中运行`Pipenv install`。

为了避免部署和本地之间的依赖问题,建议将Pipfile和Pipfile.lock都推送到版本控制中。

<details>
<summary>英文:</summary>

The problem has been resolved! It was a problem caused by the different Python version between the local(mac M1 silicon) and the distribution environment. The base virtual environment was run automatically because the conda was used in the local environment and was created in version 3.9.

There may be people who have experienced the same problem as me, so I leave a solution below.

1. Clear all Pipfile, Pipfile.lock in the server environment and reinstall the package
2. git pull, remove all created virtual environments including conda from local environment
3. Create a virtual environment with `$pipenv --python 3.10` that matches the deployment environment
4. Pipenv install in local environment

To avoid any dependency issues between deployment and local , recommend pushing both Pipfile and Pipfile.lock.

</details>



# 答案2
**得分**: 0

对我来说,发生的事情是一个包被添加到了Pipfile中,但在Pypi中并不存在。出于某种原因,它没有报告存在无效的包,而只是返回了这个无用的消息。

我删除了当前的Pipfile.lock文件,修改了我的Pipfile并找到了问题所在。
我删除了有问题的那一行,并使用pipenv sync,一切都恢复正常了。

<details>
<summary>英文:</summary>

For me, what happened is that a package was added to Pipfile but it did not exist in Pypi. For some reason, instead of failing saying there was an invalid package, it just returned me this unhelpful message.

I removed the current Pipfile.lock and revised my Pipfile and found the culprid.
I removed the faulty line and used pipenv sync and everything worked again.

</details>



huangapple
  • 本文由 发表于 2023年7月10日 15:19:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76651490.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定