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

耗尽温柔 提交于 2021-02-05 03:23:49

问题


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:


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:

  • https://bitbucket.org/pypa/setuptools/issues/230
  • https://bitbucket.org/tarek/distribute/issues/177
  • https://github.com/pypa/pip/issues/126


来源:https://stackoverflow.com/questions/30737431/module-found-in-install-mode-but-not-in-develop-mode-using-setuptools

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!