4

I created a fork from this git repo: https://github.com/QQuick/Opy

I added an __init__.py to the opy directory / package. When I run setup.py install, the opy package is not installed into my site-packages directory. Why?

Here's the setup.py script:

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 = '[email protected]',
    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',
    ],
)

Output:

>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
9
  • What makes you think that the package is not installed? It's there, just not in the form you've expected it to be. Look for the file opy-1.1.28.1-py2.7.egg in the site-packages dir, this is the installed package. Also, to check whether the package is installed or not, you can try importing the modules: python -c "import opy; print('opy is installed')" etc. Commented Oct 16, 2018 at 7:39
  • Oh. Really? The egg is the package itself? There is a way to make setuptools install it in clear text? Commented Oct 16, 2018 at 12:22
  • An egg is just a zip archive, so you can take a look of what's inside. You can force setuptools into flat install by issuing python setup.py install --old-and-unmanageable which is effectively (almost) the same as using distutils.core.setup, but it's named so by a reason. Commented Oct 16, 2018 at 12:41
  • Thing is, the distutils package doesn't track the files that are being installed for a package, so there is no way to perform a clean uninstall afterwards - you simply don't know what files belonging to the package should be removed. This is one of the main reasons setuptools rolled its own package installer easy_install and the egg format (package as a single file), also why pip emerged as the setuptools approach also failed (but that's another story). Commented Oct 16, 2018 at 12:44
  • 1
    Do you have to use setup.py install at all? The proper alternative for that is running pip install . from the dir where setup.py resides; pip builds a wheel from the sources, including the list of files in it and then installs that built wheel; afterwards, uninstalling the package is just going thru that list and deleting each file. Works like a charm. Commented Oct 16, 2018 at 12:46

2 Answers 2

6

To sum up the statements from the comments:

setuptools.setup does its job; however, instead of just copying modules to site-packages (what distutils does), python setup.py install will build an egg file which is then installed by simply copying it to site-packages. This way, it's easy to uninstall the package afterwards by just removing the one egg file.

If you don't like the package being installed in an archive, you can:

  • do the "old and unmanageable" install:

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

    but beware that you may not be able to properly uninstall the package when doing that. Still, this command may be used e.g. in a virtual environment that you plan to remove afterwards anyway;

  • use pip as it's able to install packages from source directories:

    $ pip install dir/
    

    where dir is the directory containing the setup.py script. This is the preferred way; pip will build a wheel file first, then install it. The modules will be installed flat (written to disk as files), but pip will also store the list of installed files among other metadata, so all files will be removed properly on package uninstall.

Sign up to request clarification or add additional context in comments.

1 Comment

It's surprising (misleading) how impotent the python3 setup.py install command is.
1

I replaced

from setuptools import setup

with

from distutils.core import setup

and that worked. But, isn't the setuptools module version of that function supposed to install into the site-packages directory? The documentation indicates it does. I don't get it...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.