1

I have a python project that I want to distribute. I read multiple tutorials on how to write my setup.py file and how to install the produced wheel: sample project example, setup.py tutorial, wheel doc, wheel install or wheel install.

The structure of my project is:

project_name
    |_ lib
        |_ project_folder
        |_ py modules
    |_ test
    |_ setup.py
    |_README.rst

I build my wheel like this python setup.py bdist_wheel and then I take the produced wheel into another folder outside my project and do pip install my_wheel. I tried also pip install --no-index --find-links=my_wheel project_name

The problem is that when I look into my python site-packages folder, instead of having:

python folders
project_name
project_name-2.0.0.dist-info

the project_name folder is broken into lib and test:

python folders
lib
project_name-2.0.0.dist-info
test

I don't understand why my project_name isn't like the other python folders, grouped. Can someone help me understand better?

setup.py:

from setuptools import setup, find_packages
from codecs import open
from os import path

root_folder = path.abspath(path.dirname(__file__))

with open(path.join(root_folder, "README.rst"), encoding="utf-8") as f:
    long_description = f.read()

setup(
    name = "project",
    version = "2.0.0",

    description = "My project is cool",
    long_description = long_description,     

    packages = find_packages(),

    include_package_data = True
)
Community
  • 1
  • 1
user3314570
  • 237
  • 4
  • 14

1 Answers1

3

find_packages() determines packages by the __init__.py files. It looks like your lib and tests directories have __init__.py files in them.

Neither your lib or tests directories are packages, remove the __init__.py files from those. That way find_packages() will only include project_folder() in the resulting distribution (source, binary or wheel).

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • I tested that way (btw you were right `lib` and `tests` weren't supposed to be packages) but I still don't have my `project_folder` as a folder, only the `project_folder-2.0.0.dist-info`. I don't see why because I have the message `installing collected packages project_folder` so I thought that I would see my folder – user3314570 Jul 19 '16 at 11:15
  • @user3314570: was the wheel cache used? I'd first build a `sdist` tarball and inspect what is being put in that, *then* try to install it as a wheel (making sure to uninstall the old and that no cached wheel is used instead). – Martijn Pieters Jul 19 '16 at 11:40
  • I'm new to this method so I don't know what is the wheel cache and how to deal with it. I've first done a sdist before wanting a wheel with `python setup.py sdist`. Inside Ihave my `project_folder` with it's lib and test folders inside as I wish. – user3314570 Jul 19 '16 at 11:45
  • Use `--no-cache-dir` to prevent the cache being used. – Martijn Pieters Jul 19 '16 at 11:46
  • @user3314570: Ah, yes, the sdist would have that. Just checking: there a `__init__.py` in `project_folder`, right? – Martijn Pieters Jul 19 '16 at 11:47
  • yes there is. This one has to be a package. So I write `pip install --no-cache-dir mywheel`? – user3314570 Jul 19 '16 at 11:50
  • Yes; you may want to include `--force-reinstall` or `--ignore-installed` too to avoid any issues with pip thinking it is already installed. – Martijn Pieters Jul 19 '16 at 12:11
  • Still no sign of my `project_folder`, only the dist-info. I tested with a fake project, very simple which only contained one package folder and the setup and it worked fine. So I tested to take out my `project_folder`out of my lib folder to test if that way it will work, but still no.. – user3314570 Jul 20 '16 at 09:05
  • At this point I can't help you any further; provide a [mcve] that reproduces the issue. – Martijn Pieters Jul 20 '16 at 10:19
  • Thank you for your help and time. I deleted the lib folder and placed directly my `project_folder`at the root and it worked. – user3314570 Jul 20 '16 at 12:54