【问题标题】:Python setuptools install is not installing a packagePython setuptools install 没有安装包
【发布时间】:2018-10-15 18:40:13
【问题描述】:

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

我在opy 目录/包中添加了一个__init__.py。当我运行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',
    ],
)

输出:

>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

【问题讨论】:

  • 是什么让你觉得包没有安装?它就在那里,只是不是你所期望的形式。在site-packages 目录中查找文件opy-1.1.28.1-py2.7.egg,这是已安装的包。另外,要检查是否安装了包,可以尝试导入模块:python -c "import opy; print('opy is installed')" 等。
  • 哦。真的吗?鸡蛋是包装本身吗?有没有办法让 setuptools 以明文形式安装它?
  • 鸡蛋只是一个压缩包,所以你可以看看里面有什么。您可以通过发出python setup.py install --old-and-unmanageable 强制setuptools 进入平面安装,这实际上(几乎)与使用distutils.core.setup 相同,但它的命名是有原因的。
  • 问题是,distutils 包不跟踪正在为一个包安装的文件,因此之后无法执行干净卸载 - 你根本不知道哪些文件应删除属于该包的。这是setuptools推出自己的包安装程序easy_installegg格式(打包为单个文件)的主要原因之一,也是pip出现setuptools方法也失败的原因(但这是另一个故事)。
  • 你必须使用setup.py install吗?正确的替代方法是从setup.py 所在的目录运行pip install .pip 从源代码构建一个轮子,包括其中的文件列表,然后安装该构建的轮子;之后,卸载软件包只是通过该列表并删除每个文件。像魅力一样工作。

标签: python setuptools


【解决方案1】:

总结来自 cmets 的陈述:

setuptools.setup 完成它的工作;然而,python setup.py install 不仅仅将模块复制到site-packagesdistutils 所做的),而是构建一个 egg 文件,然后只需将其复制到site-packages 即可安装。这样,之后只需删除一个 egg 文件即可轻松卸载软件包。

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

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

    $ python setup.py install --old-and-unmanageable
    

    但请注意,执行此操作时您可能无法正确卸载软件包。不过,可以使用此命令,例如在您打算以后删除的虚拟环境中;

  • 使用pip,因为它能够从源目录安装软件包:

    $ pip install dir/
    

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

【讨论】:

  • python3 setup.py install 命令的无能程度令人惊讶(误导)。
【解决方案2】:

我换了

from setuptools import setup

from distutils.core import setup

这很奏效。但是,该函数的 setuptools 模块版本不应该安装到 site-packages 目录中吗?文档表明确实如此。没看懂……

【讨论】:

    猜你喜欢
    • 2023-03-31
    • 2019-08-05
    • 2017-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-31
    • 1970-01-01
    相关资源
    最近更新 更多