1

I have just created a Python package and uploaded it to PyPi (goosempl). Installing the package locally works:

$ python3 setup.py install

(It installs in usr/local/lib/python3.6/site-packages).

However installing it from PyPi gives a weird error:

$ pip3 install goosempl

...
PermissionError: [Errno 13] Permission denied: '/usr/local/goosempl' 

For some reason pip tries to install in the wrong location?!?


Here is the setup.py (stripped down a bit, it still causes the error):

import atexit
from setuptools import setup

__version__ = '0.1.0'

setup(
    name              = 'goosempl',
    version           = __version__,
    author            = 'Tom de Geus',
    author_email      = 'tom@geus.me',
    url               = 'https://github.com/tdegeus/GooseMPL',
    keywords          = 'matplotlib style',
    description       = 'Style and extension functions for matplotlib',
    long_description  = '',
    license           = 'MIT',
    install_requires  = ['matplotlib>=2.0.0'],
    packages          = ['goosempl'],
    data_files        = [('goosempl/stylelib',[
        'goosempl/stylelib/goose.mplstyle'
    ])],
)

I have uploaded it to PyPi using:

$ python3 setup.py sdist
$ python3 setup.py bdist_wheel --universal
$ twine upload dist/*

(My guess in that the problem is caused by the data_files)

Tom de Geus
  • 5,625
  • 2
  • 33
  • 77
  • are you inside a virtualenv? – Nils Werner May 05 '17 at 09:08
  • @NilsWerner No I'm not. (Furthermore, I'm using the homebrew Python on Mac) – Tom de Geus May 05 '17 at 09:08
  • It may be that `data_files` is the culprit, (`goosempl/stylelib` doesn't get expanded to `/usr/local/lib/python3.6/site-packages/goosempl/stylelib` but `/usr/lib/goosempl/stylelib`). Try removing the lines and instead create a `MANIFEST.in` file containing just the line `goosempl/stylelib/goose.mplstyle`. – Nils Werner May 05 '17 at 09:13
  • Also, did you really mean `python3 install setup.py`, or rather `python3 setup.py install`? – Nils Werner May 05 '17 at 09:18
  • @NilsWerner With your directions I have solved it by changing `data_files` with `package_data` (with a slightly different syntax). But maybe you are better equipped to explain this difference, and the relation to `MANIFEST.in`? – Tom de Geus May 05 '17 at 09:23
  • `package_data` and `MANIFEST.in` are the same thing. They tell `setup.py sdist` what files besides `*.py` to include in the zip file. – Nils Werner May 05 '17 at 09:24

1 Answers1

0

With the help of @NilsWerner:

The problem was in data_files. I have changed this with package_data (which has a slightly different syntax):

package_data = {'goosempl/stylelib':[
    'goosempl/stylelib/goose.mplstyle'
]}, 

This results in the desired behavior.

Following the comments, one could also include these files in MANIFEST.in.

Tom de Geus
  • 5,625
  • 2
  • 33
  • 77