setup.py claims that my module is installed but it isn't

Question:

I have the following simple directory structure

root
 |- setup.py
 |- junie.py
 |- lucy.py

The contents of the files are as follows:

# setup.py
from distutils.core import setup

setup(
    name='mydogs',
    version='1.0',    
    py_modules=['junie', 'lucy']
)
# junie.py
def junie():
    print('Junie says hi')
# lucy.py
def lucy():
    print('Lucy says hi')

Neat. I run the build

$ python3 setup.py build
running build
running build_py
creating build
creating build/lib
copying junie.py -> build/lib
copying lucy.py -> build/lib

and the install

$ python3 setup.py install
running install
/usr/local/lib/python3.10/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
/usr/local/lib/python3.10/site-packages/setuptools/command/easy_install.py:144: EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
running bdist_egg
running egg_info
creating mydogs.egg-info
writing mydogs.egg-info/PKG-INFO
writing dependency_links to mydogs.egg-info/dependency_links.txt
writing top-level names to mydogs.egg-info/top_level.txt
writing manifest file 'mydogs.egg-info/SOURCES.txt'
reading manifest file 'mydogs.egg-info/SOURCES.txt'
writing manifest file 'mydogs.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-11-x86_64/egg
running install_lib
running build_py
creating build/bdist.macosx-11-x86_64
creating build/bdist.macosx-11-x86_64/egg
copying build/lib/junie.py -> build/bdist.macosx-11-x86_64/egg
copying build/lib/lucy.py -> build/bdist.macosx-11-x86_64/egg
byte-compiling build/bdist.macosx-11-x86_64/egg/junie.py to junie.cpython-310.pyc
byte-compiling build/bdist.macosx-11-x86_64/egg/lucy.py to lucy.cpython-310.pyc
creating build/bdist.macosx-11-x86_64/egg/EGG-INFO
copying mydogs.egg-info/PKG-INFO -> build/bdist.macosx-11-x86_64/egg/EGG-INFO
copying mydogs.egg-info/SOURCES.txt -> build/bdist.macosx-11-x86_64/egg/EGG-INFO
copying mydogs.egg-info/dependency_links.txt -> build/bdist.macosx-11-x86_64/egg/EGG-INFO
copying mydogs.egg-info/top_level.txt -> build/bdist.macosx-11-x86_64/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist/mydogs-1.0-py3.10.egg' and adding 'build/bdist.macosx-11-x86_64/egg' to it
removing 'build/bdist.macosx-11-x86_64/egg' (and everything under it)
Processing mydogs-1.0-py3.10.egg
Removing /usr/local/lib/python3.10/site-packages/mydogs-1.0-py3.10.egg
Copying mydogs-1.0-py3.10.egg to /usr/local/lib/python3.10/site-packages
mydogs 1.0 is already the active version in easy-install.pth

Installed /usr/local/lib/python3.10/site-packages/mydogs-1.0-py3.10.egg
Processing dependencies for mydogs==1.0
Finished processing dependencies for mydogs==1.0

Hopefully I am forgiven for assuming that my package is now installed, however when I try to import it I get the following

$ python3
Python 3.10.8 (main, Oct 13 2022, 10:18:28) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import mydogs
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'mydogs'
>>> 

What am I doing wrong, and why can’t python find this package?

Asked By: krc

||

Answers:

you can run your function if you type:

import junie
junie.junie()

if you want to import mydogs, you need a file called mydogs.
Anyways i would recommand you use https://setuptools.pypa.io/en/latest/userguide/quickstart.html

Because the distutils package is deprecated

Answered By: Legit007
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.