“无法从安装目录获取安装脚本的一致路径”

发布于 2025-01-08 08:10:37 字数 634 浏览 1 评论 0原文

我正在使用 pip 从 git 存储库安装包:

pip install -e git+git://github.com/knipknap/SpiffWorkflow.git@master#egg=SpiffWorkflow-dev

存储库被毫无问题地克隆,但安装失败并显示以下消息:

Running setup.py egg_info for package SpiffWorkflow
Installing collected packages: SpiffWorkflow
Running setup.py develop for SpiffWorkflow
 error: ("Can't get a consistent path to setup script from installation 
  directory", '/', '/home/fcorreia/venvs/myproj/src/spiffworkflow')

我尝试查看该项目的 setup.py,但没有取得多大成功......有什么想法吗?

I'm using pip to install a package from a git repository:

pip install -e git+git://github.com/knipknap/SpiffWorkflow.git@master#egg=SpiffWorkflow-dev

The repo gets cloned without a problem, but installation fails with this message:

Running setup.py egg_info for package SpiffWorkflow
Installing collected packages: SpiffWorkflow
Running setup.py develop for SpiffWorkflow
 error: ("Can't get a consistent path to setup script from installation 
  directory", '/', '/home/fcorreia/venvs/myproj/src/spiffworkflow')

I have tried taking a look to the project's setup.py, but without much success... Any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

家住魔仙堡 2025-01-15 08:10:37

对于未来的人来说,如果您在 Windows 10 上使用旧版本的 setuptools 并且看起来有一个额外的斜杠,您需要更新 python 包“setuptools”来解决这个问题 windows 10 python bug

您可以通过多种方式更新,但其中一种是 python -m pip install --upgrade安装工具

For future folk, if you're using an older version of setuptools on windows 10 and it looks like it has an extra slash, you need to update the python package 'setuptools' to get around this windows 10 python bug

you can update any number of ways, but one is python -m pip install --upgrade setuptools

不乱于心 2025-01-15 08:10:37

您的包中需要有一个 pyproject.toml 文件。我不知道为什么这会使错误消失,但它确实有效。此文件是 PEP 518“指定 Python 项目的最低构建系统要求”的一部分

如果您的项目中有 pyproject.toml ,您可以将包放在 src 子文件夹中:

/src/yourpackage/__init__.py
/setup.py
/pyproject.toml

我不知道为什么会这样,但它会使错误消息消失当您运行 pip install -e . 以“可编辑”模式安装软件包时。该文件甚至不需要包含任何内容,它可以是一个空白文件,错误就会消失。

(为了弄清楚这一点,我发现了一个工作项目,其包存储在 src 文件夹下,并不断删除内容,直到出现该错误。这显然是 Pip 中的一些错误。我的版本是 18.1我的机器上运行的是 Windows 10 for Python 3.7。)

You need to have a pyproject.toml file in your package. I have no idea why this makes the error go away, but it works. This file is part of PEP 518 "Specifying Minimum Build System Requirements for Python Projects".

You can have your package in a src subfolder if you have a pyproject.toml in your project:

/src/yourpackage/__init__.py
/setup.py
/pyproject.toml

I have no idea why this works, but it makes the error message go away when you run pip install -e . to install the package in "editable" mode. The file doesn't even have to have anything in it, it can be a blank file and the error goes away.

(To figure this out, I found a working project that had its package stored under a src folder and kept deleting things until I got that error. This is clearly some bug in Pip. I have version 18.1 on Windows 10 for Python 3.7 on my machine.)

香橙ぽ 2025-01-15 08:10:37

这是因为 -e 标志表示“可编辑”,并且与 python setup.pydevelop 相同,它从 创建符号链接; 到您的 site-packages 目录,并且不运行常规安装。

查看 SpiffWorkflow 的 setup.py 我可以看到问题出在哪里:

srcdir = join(dirname(__file__), 'src')
setup(...,
      package_dir      = {'': srcdir})

它说包内容位于 src,而不是 spiffworkflow (开发模式期望什么)。

您只需删除 -e 标志即可:

pip install git+git://github.com/knipknap/SpiffWorkflow.git@master#egg=SpiffWorkflow-dev

参考资料:

It is because the flag -e means "editable", and it is the same doing python setup.py develop, that creates a symbolic link from <PACKAGE_NAME_LOWERCASE> to your site-packages directory and not running an usual installation.

Looking at SpiffWorkflow's setup.py I can see where the problem relies:

srcdir = join(dirname(__file__), 'src')
setup(...,
      package_dir      = {'': srcdir})

It says that the package content is located at src, instead of spiffworkflow (what develop mode expects).

You can just drop the -e flag and be happy:

pip install git+git://github.com/knipknap/SpiffWorkflow.git@master#egg=SpiffWorkflow-dev

References:

放飞的风筝 2025-01-15 08:10:37

就我而言,问题在于 package_dir = {'': './src'}:我已指定 dir 的 path,而不是 dir name >,出于某种原因,它与 setup.py bdist_wheel 配合得很好。

In my case problem was with package_dir = {'': './src'}: I have specified path to dir, rather than dir name, which for some reason worked fine with setup.py bdist_wheel.

莫多说 2025-01-15 08:10:37

我的项目有以下结构:

+-- project/
    +-- src/
    |   +-- project/
    |       +-- __init__.py
    +-- doc/
    +-- tests/
    +-- setup.py
    +-- ...

基本上,所有 python 代码都在 /src/project 中。这可以避免从测试脚本或其他脚本中直接导入project

setup.py 内容:

setuptools.setup(
    ...
    packages=setuptools.find_packages('src'),
    package_dir={'': 'src'},
    ...
)

现在我想将所有这些都拉到下面一层,以便整个项目可以有不同的组件,如下所示:

+-- project/
    +-- backend/
    |   +-- src/
    |       +-- project/
    |           +-- __init__.py
    |
    +-- frontend/
    |   +-- ...
    |
    +-- doc/
    +-- tests/
    +-- setup.py
    +-- ...

所以当我尝试 pip install -e .,即使在尝试修复所有路径之后也是如此。

我通过更新 setup.py 解决了这个问题:

setuptools.setup(
    ...
    packages=setuptools.find_packages('backend/src'),
    package_dir={'': 'backend/src'},
    ...
)

希望这有帮助!

I had the followng structure for my project:

+-- project/
    +-- src/
    |   +-- project/
    |       +-- __init__.py
    +-- doc/
    +-- tests/
    +-- setup.py
    +-- ...

So basically, all python code in /src/project. This permits to avoid project to be directly imported from tests scripts or whatever.

setup.py content:

setuptools.setup(
    ...
    packages=setuptools.find_packages('src'),
    package_dir={'': 'src'},
    ...
)

Now I want to pull all this one level below, so that the overall project can have different components, as follows:

+-- project/
    +-- backend/
    |   +-- src/
    |       +-- project/
    |           +-- __init__.py
    |
    +-- frontend/
    |   +-- ...
    |
    +-- doc/
    +-- tests/
    +-- setup.py
    +-- ...

So I got the error message as in OP when trying to pip install -e ., even after trying to fix all paths.

I solved it by following update in setup.py:

setuptools.setup(
    ...
    packages=setuptools.find_packages('backend/src'),
    package_dir={'': 'backend/src'},
    ...
)

Hope this helps!

初懵 2025-01-15 08:10:37

就我而言,https://github.com/quiver-team/torch-quiver/blob/main/setup.py
我从包目录配置的开头删除了 ./ 字符。

# package_dir = './srcs/python'
package_dir = 'srcs/python'

而且我安装成功了。
参考https://github.com/pypa/setuptools/discussions/3755

In my cases, https://github.com/quiver-team/torch-quiver/blob/main/setup.py
I remove the ./ chars from the beginning of my package dir configuration.

# package_dir = './srcs/python'
package_dir = 'srcs/python'

And I install it successfully.
refer to https://github.com/pypa/setuptools/discussions/3755

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文