3

I create a very simple python project include empty foo.py and setup.py:

setup( # ...
    name='any_name',
    version='1.4',
    py_modules=['foo']
# ...
)

Then distribute it to my local pypi repo (Nexus): $ python setup.py sdist upload -r mypypi.
There is a setup.py in the zip file on the repo.
And install to my current folder: $ pip install --target=. any_name.
There are no setup.py in the installed folder.
I want setup.py must be in the installed folder. Is this correct?

Thanks!

2
  • Could you elaborate a little bit why you want setup.py to be available in your installed folder? This file is only required to install a package, not to run it. Commented Apr 10, 2018 at 10:07
  • I want to distribute my source include all code in setup.py. Commented Apr 10, 2018 at 10:31

1 Answer 1

1

edited: I completely revised my answer to make things easier (I hope).

setup.py is not required to be installed, it's only required to install the package. By default, when a distribution is created based on a setup.py, it already includes several files and/or directories (e.g. modules referenced in packages parameter of ´setup(...),setup.py,*.txt` files, and so on). A complete list of files that are automatically bundled in a distribution can be found here: https://docs.python.org/3.6/distutils/sourcedist.html#specifying-the-files-to-distribute

If you need to specify other files or directories that should be part of your distribution, you can either define the package_data and/or data_files parameters when calling setup(...). See ttps://docs.python.org/3.6/distutils/setupscript.html#distutils-installing-package-data for more information about the expected format of package_data and data_files.

You can also define a MANIFEST.in file to list all the files and directories that need to be part of your distribution. By default, all the files that are listed in package_data and data_files will be automatically appended to the ones listed in MANIFEST.in.

Notice that all the files defined in MANIFEST.in will be part of your distribution, but not necessarily included when your package is installed. For what I understood from Python packaging documentation: - Files listed in package_data and data_files will be automatically copied upon installation; - Files listed in MANIFEST.in will be copied only if include_package_data parameter to setup(...) is set to True.

However, please note that files listed in package_data are only included in your installation if you're not using sdist (i.e. only for binary distribution). As a consequence, it's safer to always rely on MANIFEST.in combined with include_package_data=True.

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

4 Comments

And if you simply put setup.py in MANIFEST.in?
Yes, I also tried to create a myfile.txt in root package then include *.txt. Those files were added to .zip file on repo but those are not in installed folder.
What about package_data and data_files parameters for setup(...)? (see docs.python.org/3.6/distutils/…). I didn't see you wanted to create an sdist.
I updated my answer to clarify the way you can bundle files to your package, at "distribution creation" time and at installation time. In your case, I think a simple include_package_data=True will do the trick, as setup.py is automatically added to the manifest of your package by setuptools.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.