【问题标题】:Problem installing my own package in Editable mode在可编辑模式下安装我自己的包时出现问题
【发布时间】:2022-01-24 17:49:52
【问题描述】:

我尝试使用以下命令安装我自己的软件包:pip install -e .,但我收到一条很长的错误消息,并附在末尾。
我尝试在 vscode 和 pycharm 上运行代码,但问题仍然存在。
我在第一台计算机上启动了这个包,版本是:
setuptools: 59.5.0 pip: 21.3.1 python: 3.9
在第二台计算机上我遇到了这个问题。
它的版本是:
setuptools: 58.1.0 pip: 21.2.4 python: 3.9
然后我在新的第三台计算机上尝试了相同的文件,它工作得很好,版本: setuptools: 47.1.0 pip: 20.1.1 python: 3.8
我附上了可能有助于理解问题的相关文件。
所有电脑的操作系统都是Windows,但第一台和第三台是英文版,第二台不是。我认为这可能是问题所在,但如果确实是这种情况,我不确定也不知道如何解决这个问题

setup.py:

from setuptools import setup

if __name__ == "__main__":
    setup()

setup.cfg:

[metadata]
name=Mice
version=0.0.1
author=J. Random Hacker
author_email=jrh@example.com

[options]
packages=mice
install_requires=
    typing_extensions >= 4.0.1

python_requires = >=3.6
package_dir =
    =src
long_description=open('README.txt').read()

[options.extras_require]
testing =
    pytest>=6.0

[options.package_data]
mice = py.typed

[flake8]
max-line-length=180

ignore=
    F401 # A module has been imported but is not used anywhere in the file.
    E302 # Two blank lines are expected between functions and classes.

我得到的完整错误是:

(myenv) D:\local_github\Mice>pip install -e .
Obtaining file:///D:/local_github/Mice
ERROR: Exception:
Traceback (most recent call last):
  File "D:\local_github\Mice\myenv\lib\site-packages\pip\_internal\cli\base_command.py", line 173, in _main
    status = self.run(options, args)
  File "D:\local_github\Mice\myenv\lib\site-packages\pip\_internal\cli\req_command.py", line 203, in wrapper
    return func(self, options, args)
  File "D:\local_github\Mice\myenv\lib\site-packages\pip\_internal\commands\install.py", line 315, in run
    requirement_set = resolver.resolve(
  File "D:\local_github\Mice\myenv\lib\site-packages\pip\_internal\resolution\resolvelib\resolver.py", line 75, in resolve
    collected = self.factory.collect_root_requirements(root_reqs)
  File "D:\local_github\Mice\myenv\lib\site-packages\pip\_internal\resolution\resolvelib\factory.py", line 471, in collect_root_requirements
    req = self._make_requirement_from_install_req(
  File "D:\local_github\Mice\myenv\lib\site-packages\pip\_internal\resolution\resolvelib\factory.py", line 433, in _make_requirement_from_install_req
    cand = self._make_candidate_from_link(
  File "D:\local_github\Mice\myenv\lib\site-packages\pip\_internal\resolution\resolvelib\factory.py", line 189, in _make_candidate_from_link
    self._editable_candidate_cache[link] = EditableCandidate(
  File "D:\local_github\Mice\myenv\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 321, in __init__
    super().__init__(
  File "D:\local_github\Mice\myenv\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 156, in __init__
    self.dist = self._prepare()
  File "D:\local_github\Mice\myenv\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 227, in _prepare
    dist = self._prepare_distribution()
  File "D:\local_github\Mice\myenv\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 331, in _prepare_distribution
    return self._factory.preparer.prepare_editable_requirement(self._ireq)
  File "D:\local_github\Mice\myenv\lib\site-packages\pip\_internal\operations\prepare.py", line 622, in prepare_editable_requirement
    dist = _get_prepared_distribution(
  File "D:\local_github\Mice\myenv\lib\site-packages\pip\_internal\operations\prepare.py", line 60, in _get_prepared_distribution
    abstract_dist.prepare_distribution_metadata(finder, build_isolation)
  File "D:\local_github\Mice\myenv\lib\site-packages\pip\_internal\distributions\sdist.py", line 34, in prepare_distribution_metadata
    self._setup_isolation(finder)
  File "D:\local_github\Mice\myenv\lib\site-packages\pip\_internal\distributions\sdist.py", line 61, in _setup_isolation
    self.req.build_env = BuildEnvironment()
  File "D:\local_github\Mice\myenv\lib\site-packages\pip\_internal\build_env.py", line 103, in __init__
    fp.write(textwrap.dedent(
  File "D:\yohai_new\python_folder\Python\Python39\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 589-591: character maps to <undefined>

【问题讨论】:

  • 我们需要更多细节。我只能假设您使用 setuptools 进行打包,如果是,我们可能需要查看您的 setup.py 文件?您使用的是什么 Python 解释器、操作系统等? -- 另外请使用path/to/pythonX.Y -m pip install -e . 以确保您使用的是正确的 Python 解释器。
  • 感谢您的回答,我已经更新了我的问题。现在好点了吗?
  • 也许添加完整的错误信息。
  • @sinoroc 我编辑了这个问题,如果仍然缺少重要的东西,就这么说吧:) 提前非常感谢
  • 不知道,恐怕... 看起来像是带有编码的东西,但是什么?很难说。我找到了somewhat similar issue here,也许一些变通办法可以适用于你的情况。 -- 错误输出中的路径是否准确或在粘贴之前已编辑? -- 否则,通常:尝试更新 pip 和/或 setuptools。

标签: python pip setuptools setup.py python-packaging


【解决方案1】:

setup.cfglong_description 键位于错误的部分,其值无效。

它应该在[metadata] 部分(不在[options]),它应该类似于以下内容:

[metadata]
# ...
long_description = file: README.txt
long_description_content_type = text/plain

参考文献

【讨论】:

  • 我不认为问题出在文件上,因为今天我尝试在第三台计算机上安装相同的文件并且效果很好。与第二台计算机的唯一区别是第二台计算机上的操作系统是 windows 但不是英文的,也许这就是问题所在?我没有看到出现错误的第二台计算机与运行正常的第三台计算机之间有任何其他区别
  • @niroo 你需要检查每台机器上使用了哪些 setuptools 和 pip 版本。
  • 我附上了代码工作的两台计算机的版本。有问题的第二台计算机的版本将在今天晚些时候上传(也包含整个错误消息)。然后我将使用所有数据编辑我的问题。需要更多关于我的机器的数据吗?第一台计算机:setuptools:59.5.0 pip:21.3.1 python:3.9 第三台计算机:setuptools:47.1.0 pip:20.1.1 python:3.8
  • @niroo 问题很可能在文件中。执行@sinoroc 所写的操作并尝试像这样指定 README 的编码:long_description = file:README.txt long_description_content_type = text/plain; charset-UTF-8
猜你喜欢
  • 2019-09-05
  • 2020-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-20
  • 1970-01-01
  • 2021-12-11
  • 1970-01-01
相关资源
最近更新 更多