简体   繁体   中英

Can't get distutils working

I've written a Python script that uses a package that I've created. I need to package it, so I can install it on several servers, but I can't get setup.py to find my scripts.

There's two parts to my script: connections.py and a module that is imported as X.utils.printing (where X is my group name). I need to bundle both with distutils.

I've read the Python Distutils documentation about five times, and I just don't get it.

Here's what I need to do: 1) Make sure that my printing module is installed and can be imported with

from X.utils.printing import PrettyPrint as PP

2) Put connections.py in /usr/sbin/

This should be very straightforward, but it's become maddening.

Here's my current setup.py that doesn't work:

from distutils.core import setup

setup(name='connections', version='0.1.1', 
      description='Print number of IHS connections',    
      author='fandingo', author_email='fandingo@fandingo.com', 
      package_dir = {'X.utils' : 'X'}, 
      packages=['X.utils.printing'], py_modules=['printing', 'connections'])

setup.py resides and is run from a directory called 'python' and has connection-stats/ and X inside. connection-stats has connections.py inside. X has init .py, utils/ init .py, and utils/printing.py.

When I try to run setup.py, I get the following output:

python setup.py bdist

running bdist running bdist_dumb

running build running build_py file

printing.py (for module printing) not

found file connections.py (for module

connections) not found error: package

directory 'X/printing' does not exist

Could someone help me fix my setup.py, so I can package my script and module?

Thanks for all the help.

Edit: I haven't made any attempt to copy connections.py to /usr/sbin/. I haven't gotten beyond distutils not finding my modules.


Edit 2: I think that I'm getting much closer, but I can't get my package hierarchy to work.

Using,

setup(name='connections', version='0.1.1', description='Print number of IHS connections',
      author='fandingo', author_email='fandingo@fanding.com',
      package_dir = {'printing' : 'X/utils'}, packages=['printing'], 
      scripts=['connection-stats/connections.py'])

I get a successful build that has connections.py in what should become /usr/sbin/ when an installation is performed. The only problem is that printing gets imported without the X.utils.printing.

I can change it to include X, but it doesn't include child packages.

setup(name='connections', version='0.1.1', 
      description='Print number of IHS connections', 
      author='fandingo', 
      author_email='fandingo@fandingo.com', 
      packages=['X'],
      scripts=['connection-stats/connections.py'])

The problem here is that X is imported, but only the init .py. utils/ isn't included, which means I don't get utils/printing.py

It's like I need some sort of recursive option, so I can add X and everything below it. Any thoughts?

Thanks,

----------------------

Edit 3:

Just about completed. I figured out that I need to explicitly list every sub-package in X. Here's the corrected setup.py

setup(
    name='connections',
    version='0.1.1',
    description='Print number of IHS connections',
    author='fandingo',
    author_email='fandingo@fandingo.com',
    package_dir = {'utils' : 'X/', 'printing' : 'X/utils/'},
    packages=['X', 'X.utils'],
    py_modules = ['printing'],
    scripts=['connection-stats/connections.py'])

The only other thing is that connections.py isn't moved to /usr/sbin/. I think that I will just add a post-install option to manually move it.

I think you'll want something like the following:

from distutils.core import setup

setup(name='connections',
      version='0.1.1',
      description='Print number of IHS connections',
      author='fandingo',
      author_email='fandingo@fandingo.com',
      packages=['X'],
      scripts=['connection-stats/connections.py'])

UPDATE: fix packages list

Your packages, py_modules and package_dir settings are way too complicated. Let's step back. What is the file structure you want to distribute? If I understand correctly, it is a X package with an X.utils subpackage which contains an X.utils.printing module. Thus, your call to setup should read setup(..., packages=['X', 'X.utils']. IOW, distutils does not include all packages in a package (you have to specify X.utils) but it includes all modules in a package (you don't have to specify py_modules=['X.utils.printing']). Can you test that?

Second, there is no support for sbin in distutils. We're working on that for distutils2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM