Zeratas
Zeratas

Reputation: 1015

Python setup.py script isn't installing modules correctly

Repo location: https://github.com/willkara/SakaiPy

So I have this python modudle I'm creating. It currently has this structure:

SakaiPy
├── SakaiPy
│   ├── __init__.py #1
│   └── RequestGenerator.py
├── SakaiTools
    ├── __init__.py #2
    ├── Assignment.py
    ├── Announcement.py
    └── ...etc.py
└── setup.py

init.py #1 looks like:

__all__=['SakaiTools']
from SakaiTools import *

init.py #2 is empty

My setup.py looks like:

  version='1.0',
  description='Python interface to the Sakai RESTful API\'s',
  license='MIT',
  author='William Karavites',
  author_email='[email protected]',
  url='https://github.com/willkara/SakaiPy',
  packages=['SakaiPy','SakaiPy/SakaiTools'],
  requires={
            "mechanize",
            "cookielib",
            "requests",
            "simplejson"}
 )

My problem is that the module seems to be building incorrectly.

When I try and use the module like this:

#!/usr/bin/python
# -*- coding: utf-8 -*-

from SakaiPy import *

print "hello"

authInfo={}
authInfo['baseURL'] =""
authInfo['loginURL']=""
authInfo['username']=""
authInfo['password']=""

rq = RequestGenerator.RequestGenerator(authInfo)

I get this error:

Traceback (most recent call last):
  File "../sakaiTest.py", line 14, in <module>
    rq = RequestGenerator.RequestGenerator(authInfo)
NameError: name 'RequestGenerator' is not defined

My guess is that my setup.py and init.py scripts are setup incorrectly.

Upvotes: 0

Views: 637

Answers (1)

Kevin Brown-Silva
Kevin Brown-Silva

Reputation: 41719

You are going to want to change your directory stucture, as right now you technically have two Python modules and you are giving setuptools an incorrect package path. In order to get the path you are looking for, you are going to need to nest the SakaiTools directory within the SakaiPy directory. With this, you should be able to have the import you are looking for, and you can import SakaiTools as SakiPy.SakaiTools like you appear to be try to do.

SakaiPy
├── SakaiPy
│   ├── __init__.py # make this blank
│   ├── RequestGenerator.py
│   └── SakaiTools
│       ├── __init__.py # keep it blank
│       ├── Assignment.py
│       ├── Announcement.py
│       └── ...etc.py
└── setup.py

This will give you a single module with SakaiTools as a submodule, which sounds like what you are looking for. You are going to need to remve you SakaiTools imports from the first __init__.py, as you will be able to access those imports just fine with this setup.


If you are looking to keep the two different modules, you are going to need to tell setuptools that you have two different modules.

version='1.0',
description='Python interface to the Sakai RESTful API\'s',
license='MIT',
author='William Karavites',
author_email='[email protected]',
url='https://github.com/willkara/SakaiPy',
packages=['SakaiPy','SakaiTools'],
requires=(
    "mechanize",
    "cookielib",
    "requests",
    "simplejson",
)

Upvotes: 2

Related Questions