Python setuptools install 没有安装包

Buv*_*inJ 4 python setuptools

我从这个 git 存储库创建了一个分支:https ://github.com/QQuick/Opy

我将一个添加__init__.py到目录/包中opy。当我运行时setup.py install,该opy包没有安装到我的site-packages目录中。为什么?

这是 setup.py 脚本:

import os
import sys

sys.path.append ('opy')
import opy

from setuptools import setup
import codecs

def read (*paths):
    with codecs.open (os.path.join (*paths), 'r', encoding = 'utf-8') as aFile:
        return aFile.read()

setup (
    name = 'Opy',
    version = opy.programVersion,
    description = 'OPY - Obfuscator for Python, string obfuscation added, keyword added',
    long_description = (
        read ('README.rst') + '\n\n' +
        read ('license_reference.txt')
    ),
    keywords = ['opy', 'obfuscator', 'obfuscation', 'obfuscate', 'kivy', 'pyo', 'python'],
    url = 'https://github.com/JdeH/Opy/',
    license = 'Apache 2',
    author = 'Jacques de Hooge',
    author_email = 'jacques.de.hooge@qquick.org',
    packages = ['opy'], 
    include_package_data = True,
    install_requires = [],
    classifiers = [
        'Development Status :: 5 - Production/Stable',
        'Intended Audience :: Developers',
        'Natural Language :: English',
        'License :: Other/Proprietary License',
        'Topic :: Software Development :: Libraries :: Python Modules',
        'Operating System :: OS Independent',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
    ],
)
Run Code Online (Sandbox Code Playgroud)

输出:

>python setup.py install
running install
running bdist_egg
running egg_info
creating Opy.egg-info
writing Opy.egg-info\PKG-INFO
writing top-level names to Opy.egg-info\top_level.txt
writing dependency_links to Opy.egg-info\dependency_links.txt
writing manifest file 'Opy.egg-info\SOURCES.txt'
reading manifest file 'Opy.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no previously-included files matching '*.pyc' found anywhere in distribution
warning: no previously-included files matching '*.des' found anywhere in distribution
writing manifest file 'Opy.egg-info\SOURCES.txt'
installing library code to build\bdist.win32\egg
running install_lib
running build_py
creating build
creating build\lib
creating build\lib\opy
copying opy\opy.py -> build\lib\opy
copying opy\opymaster.py -> build\lib\opy
copying opy\__init__.py -> build\lib\opy
creating build\bdist.win32
creating build\bdist.win32\egg
creating build\bdist.win32\egg\opy
copying build\lib\opy\opy.py -> build\bdist.win32\egg\opy
copying build\lib\opy\opymaster.py -> build\bdist.win32\egg\opy
copying build\lib\opy\__init__.py -> build\bdist.win32\egg\opy
byte-compiling build\bdist.win32\egg\opy\opy.py to opy.pyc
byte-compiling build\bdist.win32\egg\opy\opymaster.py to opymaster.pyc
byte-compiling build\bdist.win32\egg\opy\__init__.py to __init__.pyc
creating build\bdist.win32\egg\EGG-INFO
copying Opy.egg-info\PKG-INFO -> build\bdist.win32\egg\EGG-INFO
copying Opy.egg-info\SOURCES.txt -> build\bdist.win32\egg\EGG-INFO
copying Opy.egg-info\dependency_links.txt -> build\bdist.win32\egg\EGG-INFO
copying Opy.egg-info\top_level.txt -> build\bdist.win32\egg\EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist\Opy-1.1.28.1-py2.7.egg' and adding 'build\bdist.win32\egg' to it
removing 'build\bdist.win32\egg' (and everything under it)
Processing Opy-1.1.28.1-py2.7.egg
Copying Opy-1.1.28.1-py2.7.egg to c:\python27\lib\site-packages
Adding Opy 1.1.28.1 to easy-install.pth file

Installed c:\python27\lib\site-packages\opy-1.1.28.1-py2.7.egg
Processing dependencies for Opy==1.1.28.1
Finished processing dependencies for Opy==1.1.28.1
Run Code Online (Sandbox Code Playgroud)

hoe*_*ing 6

总结一下评论中的陈述:

setuptools.setup尽其职责;然而,不是仅仅将模块复制到site-packagesdistutils做什么),而是python setup.py install构建一个 Egg 文件,然后通过简单地将其复制到site-packages. 这样,之后只需删除一个 Egg 文件即可轻松卸载该软件包。

如果您不喜欢将软件包安装在存档中,您可以:

  • 进行“旧且难以管理”的安装:

    $ python setup.py install --old-and-unmanageable
    
    Run Code Online (Sandbox Code Playgroud)

    但请注意,执行此操作时您可能无法正确卸载该软件包。尽管如此,该命令仍然可以在例如您计划随后删除的虚拟环境中使用;

  • 使用pip它可以从源目录安装包:

    $ pip install dir/
    
    Run Code Online (Sandbox Code Playgroud)

    其中dir是包含脚本的目录setup.py。这是首选方式;pip将首先构建一个wheel文件,然后安装它。这些模块将被平面安装(作为文件写入磁盘),但pip还将在其他元数据中存储已安装文件的列表,因此所有文件都将在软件包卸载时正确删除。