gpt4 book ai didi

How to build a python package with setup.py?(如何使用setup.py?构建Python包)

转载 作者:bug小助手 更新时间:2023-10-27 19:58:03 24 4
gpt4 key购买 nike



I'm trying to build package so that i can install it simply with pip3 command. It is an open-source project. Can someone please suggest me how to make it work.

我正在尝试构建包,以便我可以简单地使用PIP3命令进行安装。这是一个开源项目。有没有人能告诉我怎么做才行。


This is content of my setup.py

这是我的setup.py的内容


from setuptools import setup, find_packages

setup(
name='hawkeye',
version='0.1.0',
description='A powerful scanner to scan your Filesystem, S3, MySQL, Redis, Google Cloud Storage and Firebase storage for PII and sensitive data.',
url='e',
author='Rohit Kumar',
author_email='',
packages=find_packages('src'),
package_dir={'': 'src'},
entry_points={
'console_scripts': [
'hawk_eye=hawk_eye:main',
],
},
license='Apache License 2.0',
install_requires=['pyyaml', 'rich', 'mysql-connector-python', 'redis', 'boto3'],

classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'Topic :: Software Development :: Build Tools',
'License :: OSI Approved :: Apache License 2.0',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
],
keywords='pii secrets sensitive-data cybersecurity scanner',
)

And this is my project structure, and i made this open-source, entire source code can be found here - https://github.com/rohitcoder/hawk-eye, you can raise a PR if you want :) but let me know how to make it work.

这是我的项目结构,我做了这个开源的,完整的源代码可以在这里找到-https://github.com/rohitcoder/hawk-eye,你可以提高公关如果你想:)但让我知道如何让它工作。


├── LICENSE
├── __init__.py
├── assets
│ ├── banner.png
│ ├── hawk-eye.jpg
│ ├── preview.png
│ └── preview2.png
├── connection.yml
├── connection.yml.sample
├── fingerprint.yml
├── hawk_eye.py
├── pyvenv.cfg
├── readme.md
├── requirements.txt
├── setup.py
└── src
├── __init__.py
└── hawk_eye
├── commands
│ ├── __init__.py
│ ├── firebase.py
│ ├── fs.py
│ ├── gcs.py
│ ├── mysql.py
│ ├── redis.py
│ └── s3.py
├── internals
│ └── system.py
└── main.py


And hawk_eye.py which is in root folder is having this content

根文件夹中的hawk_eye.py包含以下内容


import sys
import os

# Add the root directory to sys.path
root_dir = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, root_dir)

from src import main

if __name__ == '__main__':
main.main()

I'm getting this error

我收到了这个错误


  Attempting uninstall: hawkeye
Found existing installation: hawkeye 0.1.0
Uninstalling hawkeye-0.1.0:
Successfully uninstalled hawkeye-0.1.0
DEPRECATION: hawkeye is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
Running setup.py install for hawkeye ... done
Successfully installed hawkeye-0.1.0

[notice] A new release of pip is available: 23.0.1 -> 23.2.1
[notice] To update, run: pip install --upgrade pip
(venv) rohitcoder@Rohits-MacBook-Pro hawk-eye % hawk_eye
Traceback (most recent call last):
File "/Users/rohitcoder/Desktop/Projects/hawk-eye/venv/bin/hawk_eye", line 33, in <module>
sys.exit(load_entry_point('hawkeye==0.1.0', 'console_scripts', 'hawk_eye')())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/rohitcoder/Desktop/Projects/hawk-eye/venv/bin/hawk_eye", line 25, in importlib_load_entry_point
return next(matches).load()
^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.11.4/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/metadata/__init__.py", line 202, in load
module = import_module(match.group('module'))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.11.4/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
File "<frozen importlib._bootstrap>", line 1126, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
File "<frozen importlib._bootstrap>", line 1140, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'hawk_eye'
(venv) rohitcoder@Rohits-MacBook-Pro hawk-eye %

I tried restructuring the folder but everytime i am getting error like hawk_eye isn't module, it's happening for that file only, which is in root folder

我尝试重新构建文件夹,但每次都出现错误,如Hawk_Eye不是模块,它只发生在根文件夹中的文件中


更多回答

You might want to check out the official guide and the sample project by PyPA for a modern file structure.

您可能希望查看官方指南和Pypa的样例项目,以了解现代的文件结构。

Try creating a folder named "hawk_eye" and put hawk_eye.py and init.py inside it, let setup.py outside

尝试创建一个名为“Hawk_ye”的文件夹,并在其中放入Hawk_ye.py和init.py,让setup.py放在外面

Also, we'd much prefer it if you can give your directory structure as text and not as an image.

此外,如果您能以文本而不是图像的形式给出目录结构,我们会更希望如此。

Please read minimal reproducible example and try to create a new, separate project with as little as possible in it that directly reproduces the exact problem, and talk us through complete steps to reproduce it (starting with creating a new venv).

请阅读最小可重现示例,并尝试创建一个新的、独立的项目,其中包含尽可能少的内容,直接复制准确的问题,并告诉我们复制它的完整步骤(从创建新venv开始)。

@InSync I updated the structure and also provided the link of the exact source code repositories in my main question, github.com/rohitcoder/hawk-eye, can you please suggest something on this one?

@InSync我更新了结构,并在我的主要问题github.com/rohitcoder/hawk-eye中提供了确切的源代码存储库的链接,您能对此提出建议吗?

优秀答案推荐

Just solved it.

刚刚解决了这个问题。


I added below line and remove "package_dir" and it started working, i'm also not sure, why. BTW, i followed this project's https://github.com/nvbn/thefuck/ setup.py

我添加了下面的代码行并删除了“Package_dir”,它开始工作了,我也不确定为什么。顺便说一句,我关注了这个项目的https://github.com/nvbn/thefuck/设置。


packages=find_packages(exclude=['ez_setup', 'examples', 'tests', 'tests.*', 'release']),

更多回答

You shouldn't use setup.py to begin with – see the first comment to your original post.

你不应该一开始就使用setup.py--请看你最初帖子的第一条评论。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com