Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can install new PyPi module with pip, but can't import it myself?

So I’m trying to add a new script I wrote, fakesky, to PyPi as a module. I uploaded it to PyPi, and pip will let me install it successfully, but every time I try to import it, I get the following error:

ModuleNotFoundError: No module named 'fakesky'

The structure of the upload is as follows:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

fakesky ->
  setup.py
  setup.cfg
  README.txt
  LICENSE
  src ->
    __init__.py (empty file)
    fakesky.py
    results_BB.txt (necessary file that fakesky.py reads)

And the relevant files are as follows:

setup.py:

from setuptools import setup, find_packages
setup(
    name='fakesky',
    version='1.0.2',
    license='CC0 1.0',
    author="Drew Weisserman",
    author_email='drewweis@umich.edu',
    packages=find_packages('src'),
    package_dir={'': 'src'},
    url='https://github.com/drewweis/fakesky',
    keywords='sky image',
    install_requires=[
        'matplotlib',
        'numpy',
        'pandas',
        'scipy',
        'astropy'
      ],

)

setup.cfg:

[metadata]
description-file=README.md
license_files=LICENSE.rst

I performed the following commends to upload it:

[cd to inside fakesky folder]
python3 setup.py sdist
twine upload dist/*

Can anyone tell me what I’m doing wrong?

>Solution :

The directory structure is wrong. Recreate like this:

fakesky ->
  setup.py
  setup.cfg
  README.txt
  LICENSE
  src ->
    fakesky ->
      __init__.py (empty file)
      fakesky.py
      results_BB.txt (necessary file that fakesky.py reads)

By the way, I recommend to name the module differently than the top-level package name, to avoid confusing imports like from fakesky import fakesky.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading