1

I am trying to figure out how to package a python project so that I can distribute it to some co-workers. When I run python setup.py sdist --formats=zip it creates a zip that I can pip install but when I run the file it can't import the class files I created.

Here is my file structure for the project (probably not correct, but I didn't fully structure this project with packaging in mind):

├── README.md
├── requirements.txt
├── scanner
│  ├── __init__.py
│  ├── __pycache__
│  │  ├── googleSheets.cpython-35.pyc
│  │  ├── merakiJsonHandler.cpython-35.pyc
│  │  └── wifiTester.cpython-35.pyc
│  ├── credentials.json
│  ├── googleSheets.py
│  ├── info.json
│  ├── merakiJsonHandler.py
│  ├── scan.py
│  ├── whatWap.py
│  └── wifiTester.py
└── setup.py

''scan.py'' is our "main" script that brings together all the classes. Here is what my setup.py looks like:

import setuptools
setuptools.setup(name='att-scanner',
 version='0.1',
 description='Meraki Wap/Wifi Scanner',
 author='jsolum',
 author_email='*****',
 license='MIT',
 packages=setuptools.find_packages(),
 entry_points={
 'console_scripts' : [
 'mws = scanner:scan.py',],},
 install_requires=['pyspeedtest', 'requests', 'gspread', 'oauth2client',],
 include_package_data=True)

And here is my error:

Traceback (most recent call last):
 File "//anaconda/bin/mws", line 7, in <module>
 from scanner import scan
 File "//anaconda/lib/python3.5/site-packages/scanner/__init__.py", line 1, in 
<module>
 from googleSheets import SheetsController
ImportError: No module named 'googleSheets'

Why can't scan.py import googleSheets.py and what do I do to make it import that and my other classes?

asked Sep 27, 2017 at 3:36

1 Answer 1

1

from googleSheets import SheetsController is an absolute import statement, so once your package is installed, you need to either use the package name:

from scanner.googleSheets import SheetsController

Or a relative import statement

from .googleSheets import SheetsController
answered Sep 27, 2017 at 3:43
Sign up to request clarification or add additional context in comments.

3 Comments

facepalm you're right. I thought I checked that! Currently I am getting an error that says `` sys.exit(scan()) TypeError: 'module' object is not callable``. I am curious to why it's trying to call scan.py. Does scan need to be renamed to main? (I think I read something like that earlier when I was troubleshooting).
@JamesSolum I'm not 100% sure, but It looks like your entry point is set to the module, rather than a function in the module. Try something like scanner.scan:main
I just saw this comment now, but yes that was it! Thanks!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.