Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What option do I need in setup.py to create the package in the right directory?

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

like image 763
Alex Avatar asked Apr 05 '13 17:04

Alex


People also ask

How do I make a directory a Python package?

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.

What is setup py in Python 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.

Which is the right way to install new package in Python?

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.


1 Answers

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

like image 104
Alex Avatar answered Sep 18 '22 01:09

Alex