Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do tell setuptools to get my package from src/mypackage

I have a package directory setup like this

package_dir
|-src
| |-mypackage
|   |-__init__.py
|
|-setup.py

How do I set up setup.py to enable me to import mypackage

I've tried: I run python setup.py bdist_wheel where setup.py has options...

packages=find_packages(include=["src"]),
package_dir={"": "src"},

When I run pip install path/to/mypackage.whl it installs fine But when I do python -c "import mypackage" it fails with ModuleNotFoundError while python -c "import src.mypackage" is fine

like image 221
piRSquared Avatar asked Jun 14 '18 17:06

piRSquared


People also ask

How do I install Python Setuptools package?

Follow the below steps to install the Setuptools package on Linux using the setup.py file: Step 1: Download the latest source package of Setuptools for Python3 from the website. Step 3: Go to the setuptools-60.5. 0 folder and enter the following command to install the package.

What is the use of Setuptools?

Setuptools is a collection of enhancements to the Python distutils that allow developers to more easily build and distribute Python packages, especially ones that have dependencies on other packages. Packages built and distributed using setuptools look to the user like ordinary Python packages based on the distutils .

How do I get version number from setup py?

The best technique is to define __version__ in your product code, then import it into setup.py from there. This gives you a value you can read in your running module, and have only one place to define it. The values in setup.py are not installed, and setup.py doesn't stick around after installation.


1 Answers

find_packages(where='src')

Use where, not include. exclude/include are for further filtering found packages. See:

$ python
Python 2.7.13 (default, Nov 24 2017, 17:33:09) 
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from setuptools import find_packages
>>> find_packages()
[]
>>> find_packages(include=['src'])
[]
>>> find_packages(where='src')
['mypackage']
like image 130
phd Avatar answered Sep 28 '22 04:09

phd