4

I am trying to add data_file to setup.py project . I can use file from /tmp/ directory, and cannot use it from current directory of the script:

from setuptools import setup, find_packages
import os

packages = find_packages("src")
foo_path = os.path.dirname(os.path.abspath(__file__)) + '/foo.dat'
print foo_path   # file exists and there full absolute path is printed:
                 # '/home/loom/myapp/foo.dat'

setup(name='myapp',
        version='0.2.0',
        url='http://loom.st',
        author='Loom',
        author_email='[email protected]',
        package_dir={'': 'src'},
        packages=packages,
        py_modules=['my_start'],
# 1.        data_files=[('lib/python', [foo_path])],
# 2.        data_files=[('lib/python', [/tmp/foo.dat])],
        setup_cfg=True,
        )

When the line 1. is uncommented, then python setup.py bdist_rpm failed with message:

running install_data
error: can't copy '/home/loom/myapp/build/bdist.linux-x86_64/rpm/BUILD/myapp-0.2.0/foo.dat': doesn't exist or not a regular file
error: Bad exit status from /var/tmp/rpm-tmp.02mmV8 (%install)

When the line 2. is uncommented, then build is completed ok and includes foo.dat (file /tmp/foo.dat exists)

Why the line 1. induces error and how to avoid it?

8
  • Are you working under Windows or *nix? Try to remove the trailing / in /home/loom/myapp/foo.dat/ while in /tmp/foo.dat it seems to be a file and not a dir Commented Apr 25, 2016 at 13:15
  • @linusg - I am working on *nix and tmp is in the root directory and file /tmp/foo.dat exists. I'll expand question, thank you Commented Apr 25, 2016 at 13:17
  • Ah OK, thanks. Try what I added to my comment please. Commented Apr 25, 2016 at 13:18
  • Maybe defining foo_path as "./foo.dat" if it's in the same directory as the setup file?? Commented Apr 25, 2016 at 13:41
  • @linusg - error: can't copy './foo.dat': doesn't exist or not a regular file I started with it. Commented Apr 25, 2016 at 13:52

1 Answer 1

1

The problem here is, that you've given the wrong path to foo.dat, it's given as a directory:

/home/loom/myapp/foo.dat/

Just remove the trailing / at the end, so it's a path to a file:

/home/loom/myapp/foo.dat

If the file really exists, all should be fine now.

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry. It was a typo in my question I fixed. Unfortunately the problem with folder still here.
Oops, will have a look on it one more time!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.