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

时间:2016-08-13 18:02:57

标签: python ubuntu 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中。我无法在其他目录中导入软件包的模块。有没有办法全局安装它,我可以在所有目录中使用?提前谢谢....

1 个答案:

答案 0 :(得分:0)

如果我理解正确,您希望以与 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 命令。然后,除了一些虚拟环境