使用 setuptools 在安装模式下找到但不在开发模式下的模块 [英] Module found in install mode but not in develop mode using setuptools
问题描述
我是第一次使用 setuptools
,并尝试打包我的代码,以便其他人可以轻松地开发它.我在虚拟环境中运行所有东西.
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.
小问题:如何在运行 python setup.py develop
时更改 egg-link 指向的目录?
Short question: How do I change the directory that the egg-link points to when I run python setup.py develop
?
长问题:我正在开发的模块名为cops_and_robots
.当我运行 python setup.py install
时,一切正常,我可以导入我的 cops_and_robots
模块.但是,当我运行 python setup.py develop
时,运行 import cops_and_robots
失败,因为 cops_and_robots.egg-link
指向错误的目录:
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/
.
目录结构如下:
|____Downloads
| |____cops_and_robots # the whole package directory
| | |____...
| | |____requirements.txt
| | |____setup.py
| | |____src
| | | |____cops_and_robots # the python package directory
| | | |______init.py__
| | |____...
还有我的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()],
)
手动修复只是将 src/cops_and_robots
附加到 cops_and_robots.egg-link
文件,但我正在寻找一种更优雅的方法来做到这一点.
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.
推荐答案
对于您的迫切需要来说可能为时已晚,但是 setuptools devel
安装已经有这个问题很久了.幸运的是,有一个简单的解决方法可能适用于您的情况.尝试改变:
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'},
到
# Package data
packages=find_packages('src'),
package_dir={'':'src'},
在您的 setup.py
脚本中.
这种情况在 setuptools
setup.py devel
和 pip install -e
中应该可以很好地工作.
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
这篇关于使用 setuptools 在安装模式下找到但不在开发模式下的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!