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 ) 
3
  • Do your lib and test directories have __init__.py files, by any chance? Commented Jul 19, 2016 at 9:37
  • Yes they have. They musn't have it? Commented Jul 19, 2016 at 9:39
  • Nope, because they are not packages. find_packages() uses __init__.py files to detect what is a package. Commented Jul 19, 2016 at 9:55

1 Answer 1

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).

Sign up to request clarification or add additional context in comments.

10 Comments

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: 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).
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.
Use --no-cache-dir to prevent the cache being used.
@user3314570: Ah, yes, the sdist would have that. Just checking: there a __init__.py in project_folder, right?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.