Python 本地创建的包未被找到

huangapple go评论57阅读模式
英文:

Python locally created package not being found

问题

我有一个小团队在一个小的新Python项目上工作。
我创建了一个名为Environment的小包。

这个包含两个文件:
Setup.py

from setuptools import setup, find_packages

setup(name='Environment', version='1.0', packages=find_packages())  

root.py

ROOT_DIR = "STATIC_VALUE_15"

当我使用pip install -e .并在我为这个项目使用的Anaconda环境中运行项目时,我可以运行使用这个Environment包的文件。然而,当其他人使用相同的分支并执行相同的步骤时,他们会收到错误信息:

Exception has occurred: ModuleNotFoundError

他们也在他们的conda环境中运行项目,以及在vsc中以相同的方式运行。当任何人使用pip list时,我们的路径对于这个包都是正确的。

有没有关于我可以尝试和测试的建议,让它在他们的系统上工作,或者为什么它在我的系统上工作而在他们的系统上不工作呢?

英文:

I have a small team of people working on a small new Python project.
I created a small package called Environment.

This has two files:
Setup.py

from setuptools import setup, find_packages

setup(name='Environment', version='1.0', packages=find_packages())  

root.py

ROOT_DIR = "STATIC_VALUE_15"

When I use pip install -e . and then run the project within the anaconda enviroment I use for this project, I can run files that use this Environment package. However when other people use the same branch and do the same steps, they get the error:

Exception has occurred: ModuleNotFoundError

They are also using their conda environment and running the project the same way in vsc.
When anyone uses pip list, for this package our paths are all correct.

Are there any suggestions for things that I could try and test to get it to work on their system, or why it works on mine and not theirs?

答案1

得分: 2

Setup.py已被弃用,请改用pyproject.toml

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "environment"
version = "1.0.0"

您还需要遵循此文件层次结构:

package_project/
└── src/
    └── environment/
        ├── __init__.py
        └── root.py

您可以阅读Python项目打包指南。在过去,因为我忘记了一个文件或没有遵循文件层次结构,我曾经苦苦挣扎过,如果构建失败,有时您仍然可以运行或导入代码,这是由于您的Python环境。

如果您想测试它是否适用于其他人而又没有其他人,您可以使用.whl在其他环境中构建软件包并安装它,其中源代码不容易访问。

英文:

Setup.py is deprecated, use pyproject.toml instead.

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "environment"
version = "1.0.0"

You also need to follow this file hierarchy:

package_project/
└── src/
    └── environment/
        ├── __init__.py
        └── root.py

You may read Packaging Python Projects. There is plenty of room to make mistake, I struggled a lot in the past because I forgot a file, or didn't follow the file hierarchy, and if the build fail, sometime you can still run or import the code because of your python environment.

If you want to test if it works for someone else without having someone else, you can build the package and install it in an other environment where the sources are not easily accessible for python, using the .whl.

huangapple
  • 本文由 发表于 2023年2月14日 21:41:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75448691.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定