pip尝试将软件包安装在错误的位置

pip尝试将软件包安装在错误的位置

本文介绍了pip尝试将软件包安装在错误的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚创建了一个Python程序包,并将其上传到PyPi( goosempl ).在本地安装该程序包:

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

$ python3 setup.py install

(它安装在usr/local/lib/python3.6/site-packages中).

但是从PyPi安装它会产生一个奇怪的错误:

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?!?

这是setup.py(缩小一点,它仍然会导致错误):

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      = '[email protected]',
    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'
    ])],
)

我已使用以下方式将其上传到PyPi:

I have uploaded it to PyPi using:

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

(我的猜测是问题是由data_files引起的)

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

推荐答案

借助@NilsWerner:

With the help of @NilsWerner:

问题出在data_files中.我已使用package_data(语法略有不同)对此进行了更改:

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.

在注释之后,还可以将这些文件包含在MANIFEST.in中.

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

这篇关于pip尝试将软件包安装在错误的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 14:56