[英]How to install a python package globally with manual setup.py?
我正在尝试使用我编写的 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
命令。 然后,除了一些虚拟环境之外,您可以从任何地方的终端命令行获得您的软件包
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.