2017-06-23 103 views
0

我正嘗試在PyPi上上傳我的第一個軟件包。除了我的函數無法訪問包中的相關文件外,一切似乎都很好。錯誤如下。我在PyPi上的軟件包找不到相關文件

File "/Users/my_username/anaconda/lib/python3.6/site-packages/deepcut/deepcut.py", line 134, in tokenize 
with open('weight/object.pk', 'rb') as handle: 
FileNotFoundError: [Errno 2] No such file or directory: 'weight/object.pk' 

我已經檢查過,實際上pip安裝我的文件與包。以下是在我的安裝目錄/Users/my_username/anaconda/lib/python3.6/site-packages/deepcut

__init__.py 
deepcut.py 
__pycache__ 
    ... 
weight 
    best_cnn.h5 
    object.pk 

我用來創建該文件夾包由

LICENCE.txt 
MANIFEST 
MANIFEST.in 
README.rst 
setup.dfg 
setup.py 
deepcut 
    __init__.py 
    deepcut.py 
    weight 
    best_cnn.h5 
    object.pk 

的的設置文件的內容如下。

from distutils.core import setup 
import setuptools 

setup(
    name = 'deepcut', 
    packages = ['deepcut'], 
    package_dir={'deepcut': 'deepcut'}, 
    package_data={'deepcut': ['weight/*']}, 
    include_package_data=True, 
    version = '0.5.0.13', 
    install_requires=['keras', 'pandas', 'scipy', 'numpy'], 
    license='MIT', 
    description = 'A Thai word tokenization library using Deep Neural Network', 
    author = 'Rakpong Kittinaradorn', 
    author_email = '[email protected]', 
    url = 'https://github.com/rkcosmos/deepcut', 
    download_url = 'https://github.com/rkcosmos/deepcut/package/0.5.zip', 
    keywords = ['thai word segmentation deep learning neural network development'], 
    classifiers = ['Development Status :: 3 - Alpha'], 
) 

和MANIFEST.in

# Include the license file 
include LICENSE.txt 
include README.rst 

# Include the data files 
recursive-include deepcut * 

回答

1

您可以嘗試使用絕對路徑來代替。

# this will be the path that the file is stored in 
# which for you should be /Users/my_username/anaconda/lib/python3.6/site-packages/deepcut/ 
path_to_module = os.path.dirname(__file__) 

# now just join it with the file in the weight folder 
weight_path = os.path.join(path_to_module, "weight", "object.pk") 
with open(weight_path, 'rb') as handle: 
    pass 
+0

這隻適用於我,但其他人下載我的包怎麼樣? –

+0

應該不是問題 - 'path_to_module'是根據安裝包的位置動態計算的。 – phd

+0

完美!謝謝澄清。 –

相關問題