gpt4 book ai didi

python - 如何使用手动 setup.py 全局安装 python 包?

转载 作者:行者123 更新时间:2023-12-04 18:51:19 24 4
gpt4 key购买 nike

我正在尝试使用我编写的 setup.py 安装 python 包。 setup.py 如下所示:

    from setuptools import setup
try:
from setuptools import setup
except ImportError:
from distutils.core import setup

setup(
name = 'pyduino',
description = 'PyDuino project aims to make python interactive with hardware particularly arduino.',
url = '###',
keywords = 'python arduino',
author = '###',
author_email = '###',
version = '0.0.0',
license = 'GNU',
packages = ['pyduino'],
install_requires = ['pyserial'],
classifiers = [

# How mature is this project? Common values are
# 3 - Alpha
# 5 - Production/Stable
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'Topic :: Software Development :: Build Tools',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
],
scripts=['pyduino/pyduino.py'],
)

但是这个包安装在目录/usr/local/bin.我不能在其他目录中导入包的模块。有没有办法全局安装它,我可以在所有目录中使用?提前致谢....

最佳答案

如果我理解正确,您希望以与 pip install 命令相同的方式安装软件包。
首先你需要有一个合适的 setup.py,例如:

import setuptools

packages = setuptools.find_packages(where='./src')

setuptools.setup(
name="the_utility",
version="1.0",
packages=packages,
include_package_data=True,
description="Utility to execute command",
long_description=open("README.md", "r").read(),
package_dir={pkg: f"src/{pkg.replace('.', '/')}" for pkg in packages},
install_requires=[line.strip() for line in open('requirements.txt', 'r').readlines()],
extras_require={},
classifiers=[],
entry_points={
'console_scripts': [
'command_1 = module_dir.cli:function_1'
]
})
然后,您必须运行 python setup.py install命令。然后,除了一些虚拟环境外,您将可以从终端命令行处获得您的包

关于python - 如何使用手动 setup.py 全局安装 python 包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38935539/

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