Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python distutils error: "[directory]... doesn't exist or not a regular file"

Let's take the following project layout:

$ ls -R . .: package  setup.py  ./package: __init__.py  dir  file.dat  module.py  ./package/dir: tool1.dat  tool2.dat 

And the following content for setup.py:

$ cat setup.py  from distutils.core import setup   setup(name='pyproj',       version='0.1',        packages=[           'package',       ],       package_data={           'package': [               '*',               'dir/*',           ],       },      ) 

As you can see, I want to include all non-Python files in package/ and package/dir/ directories. However, running setup.py install would raise the following error:

$ python setup.py install running install running build running build_py creating build creating build/lib creating build/lib/package copying package/module.py -> build/lib/package copying package/__init__.py -> build/lib/package error: can't copy 'package/dir': doesn't exist or not a regular file 

What gives?

like image 375
Santa Avatar asked Sep 14 '10 18:09

Santa


2 Answers

In your package_data, your '*' glob will match package/dir itself, and try to copy that dir as a file, resulting in a failure. Find a glob that won't match the directory package/dir, rewriting your setup.py along these lines:

from distutils.core import setup  setup(name='pyproj',       version='0.1',        packages=[           'package',       ],       package_data={           'package': [               '*.dat',               'dir/*'           ],       },      ) 

Given your example, that's just changing '*' to '*.dat', although you'd probably need to refine your glob more than that, just ensure it won't match 'dir'

like image 52
Jacob Oscarson Avatar answered Sep 21 '22 12:09

Jacob Oscarson


You could use Distribute instead of distutils. It works basically the same (for the most part, you will not have to change your setup.py) and it gives you the exclude_package_data option:

from distribute_setup import use_setuptools use_setuptools()  from setuptools import setup  setup(name='pyproj',       version='0.1',        packages=[           'package',       ],       package_data={           'package': [               '*.dat',               'dir/*'           ],       },       exclude_package_data={           'package': [               'dir'           ],       },      ) 
like image 35
mnieber Avatar answered Sep 24 '22 12:09

mnieber