除非我删除“pyproject.toml”,否则无法使用“pip install -e”进行开发安装

问题描述 投票:0回答:2

我有以下情况,

pip install -e .
不会构建develop
版本,除非我删除不包含包装信息但包含
black
配置的
pyproject.toml

有人知道如何才能获得

develop

 版本吗?

我的

pyproject.toml

看起来像这样:

# Source https://github.com/psf/black#configuration-format [tool.black] line-length = 100 target-version = ['py38'] exclude = ''' '''

setup.py


from setuptools import find_namespace_packages from setuptools import setup setup( name="webservice", packages=find_packages(), version="0.1.0", description="description", author="Author", license="License", )
使用这两个文件运行

pip install -e .

...

(webservice_tool)pk@LAP1:~/webservice_tool$ pip install -e . Obtaining file:///home/pk/webservice_tool Installing build dependencies ... done Checking if build backend supports build_editable ... done Getting requirements to build editable ... done Preparing editable metadata (pyproject.toml) ... done Building wheels for collected packages: webservice Building editable for webservice (pyproject.toml) ... done Created wheel for webservice: filename=webservice-0.1.0-0.editable-py3-none-any.whl size=4070 sha256=dcb7c034ba437503d1059fe9370ccafbda144cd19f3e5d92340a63a7da396422 Stored in directory: /tmp/pip-ephem-wheel-cache-6iqiqbob/wheels/e6/b5/ba/40d8c3d66df94ee2ae46e181034e0c3c47132784db53284d0b Successfully built webservice Installing collected packages: webservice Successfully installed webservice-0.1.0
我删除了 

pyproject.toml

,然后 
Running setup.py develop
 才出现。

(webservice_tool) pk@LAP1:~/webservice_tool$ pip install -e . Obtaining file:///home/pk/webservice_tool Preparing metadata (setup.py) ... done Installing collected packages: webservice Attempting uninstall: webservice Found existing installation: webservice 0.1.0 Uninstalling webservice-0.1.0: Successfully uninstalled webservice-0.1.0 Running setup.py develop for webservice Successfully installed webservice-0.1.0
我的 conda env 中某些选定软件包的版本,在 wsl2 中运行

packaging 21.3 pyhd3eb1b0_0 pip 22.1.2 py38h06a4308_0 python 3.8.13 h12debd9_0 setuptools 61.2.0 py38h06a4308_0
文件夹结构

|-- data_utils | |-- clean_cache.py | `-- advanced_utils.py |-- deployment | |-- base_deployment | | |-- auth-proxy.yaml | | |-- kustomization.yaml | | |-- webapi.yaml | | `-- webui.yaml | `-- mysql_from_helm | |-- mysql-from-helm.yaml | `-- mysql-kustomization.yaml |-- docker-compose.yml |-- Dockerfile |-- environment.yml |-- live_api | |-- definitions.json | |-- __init__.py | `-- live_api.py |-- params.py |-- pyproject.toml |-- setup.py |-- shared_helpers | |-- data_cleaning.py | |-- handle_time.py | |-- __init__.py | |-- plot_timesequence.py | |-- read_samples.py | `-- save_samples.py |-- setup.py |-- util.py |-- webtool | |-- clean_data | | |-- clean_data.py | | `-- __init__.py | |-- evaluation | | |-- draw_figures.py | | |-- __init__.py | | `-- webtool_metrics.py | |-- __init__.py | |-- preprocess | | |-- __init__.py | | `-- preprocess.py | |-- ui | | |-- __init__.py | | `-- create_ui.py | `-- util | |-- data_input.py | |-- data_redefinitions.py | `-- __init__.py |-- webtool.egg-info | |-- dependency_links.txt | |-- entry_points.txt | |-- PKG-INFO | |-- SOURCES.txt | `-- top_level.txt `-- webtool_tests |-- clean_data | `-- test_clean_data.py |-- evaluation | `-- test_draw_figures.py |-- preprocess | `-- test_preprocess.py `-- util |-- test_data_input.py `-- test_data_redefinitions.py
    
python pip setuptools setup.py pyproject.toml
2个回答
3
投票
这些都是

都是开发安装。这里 pip 输出的差异是因为 pyproject.toml

 文件的存在(或不存在)会导致 pip 使用(或不使用)构建后端挂钩。从
PEP 517

如果

pyproject.toml

 文件不存在...源代码树未使用此规范,工具应恢复到运行 setup.py 的旧行为

您还可以使用 pip 命令行选项来控制:

$ pip install --help | grep pep --use-pep517 Use PEP 517 for building source distributions (use --no-use-pep517 to force legacy behaviour).
使用 PEP 517 样式构建,pip 正在设置 venv 并全新安装 setuptools,以便在幕后进行包构建(请参阅日志中的

“安装构建依赖项...完成”),而不是调用 python setup.py develop

 直接假设在用于执行 
setup.py
 文件的 Python 运行时中已经安装了足够的 setuptools 版本。这里的要点是,使用 PEP 517 风格的构建系统允许项目指定它所需的 setuptools 版本(或者,实际上,完全使用其他一些构建系统)。

最终结果将是相同的 - 放置在站点包中的 .pth

路径配置文件 会将源目录公开为开发安装。

由于

util.py

 不包含在任何包中,因此要在开发安装中选取它(而不是仅从当前工作目录导入),您还需要将其与 
find_packages()
 一起列出在 
setup
 致电:

# in setup.py from setuptools import setup setup( name="webservice", version="0.1.0", packages=find_packages(), py_modules=["util"], # <--- here ... )
    

1
投票
正如其他人已经说过的,这两个安装都是可编辑的。导入行为的差异是由在后台执行可编辑安装的方式引起的:

  • 在旧模式下,您的项目目录只需添加到

    sys.path

    ;
    (这就是 
    import util
     起作用的原因)

  • 在 PEP 660 模式下

    setuptools

     
    可以根据配置选项和您的项目结构选择不同的技术自版本 64.0.0起受支持):

    setuptools

     努力在允许用户查看正在编辑的项目文件的效果与仍然尝试保持可编辑安装尽可能与常规安装相似之间找到平衡。

    您的项目具有平面布局,因此

    setuptools

     
    安装“导入查找器”,从而 限制您的导入仅包含在分发包中的包和模块。

  • 根据您的
setup.py

,您没有在项目中指定任何模块。您需要将它们列在

py_modules
函数的
setup()
参数中。
您还可以将所有项目配置移至 
pyproject.toml
文件中。
    

© www.soinside.com 2019 - 2024. All rights reserved.