简体   繁体   English

基于打包(setup.py)的另一个文件的函数导入导致“找不到 .egg-info 目录”

[英]Function import from another file based on packaging (setup.py) leads to "No .egg-info directory found"

My goal is to access a function called train_test_split(...) from the file utils.py within dnn.py.我的目标是从 dnn.py 中的文件 utils.py 访问一个名为 train_test_split(...) 的函数。 My structure is the following:我的结构如下:

├───MachineLearning
│   └───src
│       ├───deep_learning
|           └─── dnn.py
|           └─── __init__.py
│       └───utils
|           └─── preprocessing.py
|           └─── __init__.py
│   └───readme.md
│   └───setup.py

I don't want to use or change my windows path because it should run on other computers too that clone from my github.我不想使用或更改我的 Windows 路径,因为它也应该在从我的 github 克隆的其他计算机上运行。 The solution I found is using a setup.py file.我找到的解决方案是使用 setup.py 文件。 I spent a really long time trying to understand how it works and ended up with the structure above.我花了很长时间试图理解它是如何工作的,最终得到了上面的结构。 My setup.py file contains this:我的 setup.py 文件包含以下内容:

from setuptools import setup, find_packages

setup(
    name='example',
    version='0.1.0',
    packages=find_packages()
)

Now when I run pip install -e .现在,当我运行pip install -e . from the the root folder (MachineLearning) I get the following error:从根文件夹(MachineLearning)我收到以下错误:

(tf38_clone) F:\Code\MachineLearning>pip install -e .          
Obtaining file:///F:/Code/MachineLearning
  Preparing metadata (setup.py) ... done
ERROR: No .egg-info directory found in C:\Users\Nick\AppData\Local\Temp\pip-pip-egg-info-pvq_am4y

Can anybody point me into the right direction?有人能指出我正确的方向吗? The only thing I want is to import my function into another .py file as described above.我唯一想要的是将我的函数导入到另一个 .py 文件中,如上所述。

If your如果你的

goal is to access a function called train_test_split(...) from the file utils.py within dnn.py目标是从 dnn.py 中的文件 utils.py 访问一个名为 train_test_split(...) 的函数

which you also indicated by writing你也用文字表示

The only thing I want is to import my function into another .py file as described above.我唯一想要的是将我的函数导入到另一个 .py 文件中,如上所述。

then you should try from utils import train_test_split at the beginning your dnn.py to import the function from the other module.那么你应该尝试from utils import train_test_split在一开始你dnn.py从其他模块导入的功能。 There is no need for creating a package for this use case.无需为此用例创建包。 More information about modules in python can be found here .可以在此处找到有关 Python 中模块的更多信息。

However, if you want to install an editable package, you need to build one first (ie, python -m build ), which will create *.egg-info in your stacktrace.然而,如果你想安装一个可编辑的包,你需要先构建一个(即python -m build ),它会在你的*.egg-info创建*.egg-info You can read more about packaging here .您可以在此处阅读有关包装的更多信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 pip和setup.py install不安装实际模块,仅安装egg-info - pip and setup.py install don't install actual modules, only egg-info Python“setup.py develop”:是否可以在源代码文件夹中创建“.egg-info”文件夹? - Python “setup.py develop”: is it possible to create “.egg-info” folder not in source code folder? python setup.py install 不适用于最新的 setuptools:&#39;&lt;*&gt;.egg-info&#39; 中没有脚本 - python setup.py install does not work with latest setuptools: no scripts in '<*>.egg-info' 在 macOS Big Sur 上安装 py3exiv2 失败 | 错误:在中找到 No.egg-info 目录 - Installation of py3exiv2 on macOS Big Sur fails | ERROR: No .egg-info directory found in 使用setup.py在简单目录上使用Python打包* .egg格式有什么好处和缺点? - What are the benefits and downsides of using the Python packaging *.egg format over a simple directory with setup.py? 在 MBP M1、macOS Big Sur 上安装 py3exiv2 失败 | InstallationError: No.egg-info 目录位于 - Installation of py3exiv2 fails on MBP M1, macOS Big Sur | InstallationError: No .egg-info directory found in 错误:在 /tmp/pip-pip-egg-info- 中找到多个.egg-info 目录<somehash></somehash> - ERROR: More than one .egg-info directory found in /tmp/pip-pip-egg-info-<somehash> setup.py install 运行 egg_info 错误:[Errno 13] 权限被拒绝,不管安装目录 - setup.py install running egg_info error: [Errno 13] Permission denied regarless of install directory 停止 setup.py 安装为 egg - stopping setup.py from installing as egg 为什么“python setup.py sdist”会在项目根目录中创建不需要的“PROJECT-egg.info”? - Why does "python setup.py sdist" create unwanted "PROJECT-egg.info" in project root directory?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM