[英]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.