gbriones.gdl
gbriones.gdl

Reputation: 536

Python installed package won't import modules

I want to create a python app named knife that can be executed from CLI, the problem is that it can't import the modules.

My file structure is like this:

my_project/
    knife/
        __init__.py
        knife.py
        external.py
    setup.py

My setup.py looks like this:

#!/usr/bin/python

from setuptools import setup, find_packages

setup(name='Knife',
      version='0.3',
      description='Very cool project',
      author='John Doe',
      author_email='[email protected]',
      packages=find_packages(),
      py_modules=['knife.external'],
      scripts=['knife/knife.py'],
     )

My knife.py looks like this:

#!/usr/bin/python

import external

def main():
    print("Execute main function")

if __name__ == "__main__":
    main()

So after installing the module with setup.py install, I try to run knife but keeps on throwing this error:

$ knife.py 
Traceback (most recent call last):
  File "/usr/bin/knife.py", line 4, in <module>
    __import__('pkg_resources').run_script('Knife==0.3', 'knife.py')
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 723, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1643, in run_script
    exec(script_code, namespace, namespace)
  File "/usr/lib/python2.7/site-packages/Knife-0.3-py2.7.egg/EGG-INFO/scripts/knife.py", line 3, in <module>
    __requires__ = 'Knife==0.3'
ImportError: No module named external

What is really happening? and how can I solve it?

Upvotes: 0

Views: 833

Answers (1)

Tanglim Lua
Tanglim Lua

Reputation: 68

The external.py should be shipped too. So the setup.py added the external.py:

  scripts=['knife/knife.py', 'knife/external.py'],

Upvotes: 1

Related Questions