Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.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 develope“;为什么我的数据包不可用?_Python_Setuptools - Fatal编程技术网

Python“;setup.py develope“;为什么我的数据包不可用?

Python“;setup.py develope“;为什么我的数据包不可用?,python,setuptools,Python,Setuptools,我有一个问题,在setup.py develope之后无法访问我的数据包。以下是我的设置: setup.py from setuptools import setup, find_packages from posixpath import join, relpath, normpath import os setup( name = 'poc_datapath', version = '1.0', package_dir = { '' :

我有一个问题,在setup.py develope之后无法访问我的数据包。以下是我的设置:

setup.py

from setuptools import setup, find_packages
from posixpath import join, relpath, normpath
import os

setup(
    name         = 'poc_datapath',
    version      = '1.0',
    package_dir  = { '' : 'target/python', 'resources' : 'target/res'},
    packages     = find_packages(where='target/python') + ['resources'],
    package_data = { 'resources' : [normpath(join(relpath(root.replace('\\','/'), 'target/res'),fn)) 
                                             for root, _, fnames in os.walk('target/res') for fn in fnames
                                             if not fn.endswith(".py")] },
)
这会生成一个SOURCES.txt,在我看来很不错,如下所示:

setup.py
target/res/__init__.py
target/res/resources1/resource.data
target/res/resources2/resource.data
target/python/poc_datapath.egg-info/SOURCES.txt
target/python/package1/__init__.py
target/python/package1/code.py
target/python/package2/__init__.py
target/python/package2/code.py
访问package1和package2的工作方式与预期的一样,但我无法导入resources包。为什么呢?它以前使用了类似的配置和单个数据文件,并且没有子文件夹

[编辑]

也许我没有说清楚:
尽管该文件夹中有一个
\uuuu init\uuuuuuuuy.py
,但导入资源的操作已经失败。

您需要在需要访问的每个子文件夹中创建一个
\uuuuuuuuuuuuuuy.py
文件。您已经在软件包1和2中实现了这一点。

setup.py develope
无法正确支持软件包目录,请参阅


如果文件夹的名称与包的名称不同(如果名称不同,则不起作用)。

在本例中,您应该使用
pkg_resources
加载和访问包资源。