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
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.
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 .
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.
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']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With