Module found in install mode but not in develop mode using setuptools

2k views Asked by At

I'm using setuptools for the first time, and trying to package my code so that others can easily develop it. I'm running everything in a virtual environment.

Short question: How do I change the directory that the egg-link points to when I run python setup.py develop?

Long question: The module I'm developing is called cops_and_robots. When I run python setup.py install, things work fine and I'm able to import my cops_and_robots module. However, when I run python setup.py develop, running import cops_and_robots fails because the cops_and_robots.egg-link points to the wrong directory:

(cops_and_robots)Antares:cops_and_robots nick$ cat ~/virtual_environments/cops_and_robots/lib/python2.7/site-packages/cops-and-robots.egg-link 
/Users/nick/Downloads/cops_and_robots/
.

Here's the directory structure:

|____Downloads
| |____cops_and_robots # the whole package directory
| | |____...
| | |____requirements.txt
| | |____setup.py
| | |____src
| | | |____cops_and_robots # the python package directory
| | | |______init.py__
| | |____...

And my setup.py:

from setuptools import setup, find_packages
import ez_setup
ez_setup.use_setuptools()

setup(
    # Author information and Metadata
    name='cops_and_robots',

    # Package data
    packages=find_packages('src'),
    package_dir={'cops_and_robots':'src/cops_and_robots'},
    include_package_data=True,
    platforms='any',
    requires=['std_msgs','rospy'],
    tests_require=['pytest'],
    install_requires=[i.strip() for i in open("requirements.txt").readlines()],
)

The manual fix is to just append src/cops_and_robots to the cops_and_robots.egg-link file, but I'm looking for a more elegant way to do that.

1

There are 1 answers

0
Jurko Gospodnetić On

Probably too late for your immediate need, but setuptools devel installation has had this problem for a long time. Luckily, there is an easy workaround that might work in your case. Just try changing:

# Package data
packages=find_packages('src'),
package_dir={'cops_and_robots':'src/cops_and_robots'},

to

# Package data
packages=find_packages('src'),
package_dir={'':'src'},

in your setup.py script.

That case should work well enough with setuptools setup.py devel and thus with pip install -e as well.

For some more background information on this issue, see the following links: