简体   繁体   English

python setup.py安装后的FileNotFoundError(不是在开发之后!)

[英]FileNotFoundError after python setup.py install (not after develop!)

I have a python project with the following structure:我有一个具有以下结构的python项目:

src/
  main.py
  example.txt
setup.py

After installation, I should be able to call myprogramm -name bla and it should create a new folder bla and copy example.txt inside.安装后,我应该能够调用myprogramm -name bla并且它应该创建一个新文件夹bla并在其中复制example.txt

When installing the program with python setup.py develop (inside a virtualenv) everything works fine and as expected.使用python setup.py develop (在 virtualenv 中)安装程序时,一切正常且符合预期。 However, when using python setup.py install , I get a FileNotFoundError when executing the command as Python cannot find example.txt .但是,当使用python setup.py install ,我在执行命令时收到FileNotFoundError因为 Python 找不到example.txt

Why doesn't it copy example.txt to the correct location when installing with python setup.py install ?为什么在使用python setup.py install时不将example.txt复制到正确的位置? How can I fix the problem?我该如何解决这个问题? Do I need to include example.txt explicitly in my setup.py somehow?我需要以某种方式在setup.py明确包含example.txt吗?

Including a MANIFEST.in and adding include_package_data=True in my setup.py solved my problem.包括一个MANIFEST.in在我的setup.py添加include_package_data=True解决了我的问题。

Apparently, package_data does not behave how you would expect: https://stackoverflow.com/a/14159430/2745116显然, package_data行为与您预期的不同: https : //stackoverflow.com/a/14159430/2745116

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM