Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法在setup.py中导入从git安装的依赖项_Python - Fatal编程技术网

Python 无法在setup.py中导入从git安装的依赖项

Python 无法在setup.py中导入从git安装的依赖项,python,Python,我正在尝试使用setup.py安装保存在git存储库中的Python包,我们将其称为my_dependency。在my_package中,我有一个setup.py文件,其中包含: setup( ... install_requires=[ ... 'my_dependency=VERSION' ], dependency_links=['git+https://...my_dependency.git#egg=my_dependen

我正在尝试使用setup.py安装保存在git存储库中的Python包,我们将其称为
my_dependency
。在
my_package
中,我有一个setup.py文件,其中包含:

setup(
    ...
    install_requires=[
        ...
        'my_dependency=VERSION'
    ],
    dependency_links=['git+https://...my_dependency.git#egg=my_dependency-VERSION',]
)
当我运行安装文件(
python setup.py develope
)时,依赖项似乎已安装;当我运行
pip freeze
时,它显示为
my_dependency==VERSION
。但是,当我启动python会话并调用
import my_dependency
时,我会得到
import错误:没有名为my_dependency的模块

我不知道这是否可能是问题的根源,但在运行setup.py时,我收到一条警告:

Processing dependencies for my_package==0.1
Searching for my_dependency==VERSION
Doing git clone from https://.../my_dependency.git to /var/folders/.../.../T/easy_install-_rWjyp/my_dependency.git
Best match: my_dependency VERSION
Processing my_dependency.git
Writing /var/folders/.../my_dependency.git/setup.cfg
Running setup.py -q bdist_egg --dist-dir /var/folders/.../my_dependency.git/egg-dist-tmp-UMiNdL
warning: install_lib: 'build/lib' does not exist -- no Python modules to install

Copying my_dependency-VERSION-py2.7.egg to /.../my_package/venv/lib/python2.7/site-packages
Adding my_dependency VERSION to easy-install.pth file
但是,如果我通过pip安装该软件包,我就可以使用它,比如:
pip install-e git+https://.../my_dependency.git#egg=my_dependency-版本

作为参考,依赖项包结构如下所示:

my_dependency/
    my_dependency/
        __init__.py
    setup.py
其setup.py包含以下内容:

from setuptools import setup

setup(
    name='my_dependency',
    version='VERSION',
    description='...',
    author='...',
    url='https://...',
    license='MIT',
    install_requires=[
        'numpy',
    ],

    zip_safe=False,
)
这个解决方案(回想起来)相当愚蠢。我的依赖项包的setup.py中缺少这一行:

packages=['my_dependency'],
这意味着软件包正在正确构建和安装,但实际上并没有在软件包中包含代码。当我查看egg信息中的SOURCES.txt时,这一点变得很明显:包中没有任何Python源文件