I am using setup.py
to create a python package, which I want to install via pip
. To correctly install the files under
lib/python2.7/site-packages/<package-name>
I used the following option in setup.py
:
'package_dir': {'':'lib'}
as described here but get an error
error: package directory 'lib' does not exist
Well, there is no such directory as I want the current directory to be installed as package lib
or whatever. I also tried to use
'package_dir': {'mycode':''}
which installes the code directly in
lib/python2.7/site-packages/
and not under
lib/python2.7/site-packages/<package-name>
What am I doing wrong, and where is this documented? I might overlooked the documentation of this basic feature as the documentation for setup.py
is 'suboptimal'.
Creating Packages Whenever you want to create a package, then you have to include __init__.py file in the directory. You can write code inside or leave it as blank as your wish. It doesn't bothers Python. Create a directory and include a __init__.py file in it to tell Python that the current directory is a package.
The setup.py file is at the heart of a Python project. It describes all the metadata about your project. There are quite a few fields you can add to a project to give it a rich set of metadata describing the project. However, there are only three required fields: name, version, and packages.
To install a package that includes a setup.py file, open a command or terminal window and: cd into the root directory where setup.py is located. Enter: python setup.py install.
The description to how to do this an be found in the distribute documentation... Within a directory containing all of the project (TowelStuff/
in the given example) you specify the name of the actual module (towelstuff/
). To include this as your module you need to add the following line in setup.py
:
'packages': ['towelstuff']
After having created the sdist (from within TowelStuff/
), the installation of this package will install it under site-packages/towelstuff
, which can be imported as usual (from towelstuff import ...
).
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