jsolum
jsolum

Reputation: 198

Packaging multiple Python Files: Getting Import error

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?

Upvotes: 1

Views: 757

Answers (1)

Peter Gibson
Peter Gibson

Reputation: 19534

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

Upvotes: 1

Related Questions