自定义包安装失败

问题描述 投票:0回答:1

我想让我的 Jupyter 笔记本导入自定义 Python 模块。 为此,我尝试安装一个可以导入其模块的包,例如,通过

from projectmnemonic import test
.

我的库的源代码目录结构如下:

my-datascience-project/
    ...
    notebooks/
    ...
    projectmnemonic/
        projectmnemonic/
            __init__.py
            test.py
        setup.py
    ...

setup.py
很平淡(无意发表):

from setuptools import setup

setup(
    name="projectmnemonic",
    version="0.1", 
)

我在激活的anaconda环境下安装包如下

pip install -e path/to/my-datascience-project/projectmnemonic

但出现以下错误:

Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: <redacted>
Obtaining <path to my-datascience-project/projectmnemonic>
  Preparing metadata (setup.py) ... done
Installing collected packages: <projectmnemonic>
  Running setup.py develop for <projectmnemonic>
    error: subprocess-exited-with-error

    × python setup.py develop did not run successfully.
    │ exit code: 1
    ╰─> [6 lines of output]
        running develop
        C:\ProgramData\Anaconda3\lib\site-packages\setuptools\command\easy_install.py:144: EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards-based tools.
          warnings.warn(
        C:\ProgramData\Anaconda3\lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
          warnings.warn(
        error: --egg-path must be a relative path from the install directory to <projectmnemonic>.
        [end of output]

    note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× python setup.py develop did not run successfully.
│ exit code: 1
╰─> [6 lines of output]
    running develop
    C:\ProgramData\Anaconda3\lib\site-packages\setuptools\command\easy_install.py:144: EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards-based tools.
      warnings.warn(
    C:\ProgramData\Anaconda3\lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
      warnings.warn(
    error: --egg-path must be a relative path from the install directory to <projectmnemonic>.
    [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.

当我将目录

projectmnemonic
移动到桌面并从那里安装时,我在安装过程中没有问题:

Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: <redacted>
Obtaining <path to my-datascience-project/projectmnemonic>
  Preparing metadata (setup.py) ... done
Installing collected packages: <projectmnemonic>
  Running setup.py develop for <projectmnemonic>
Successfully installed <projectmnemonic>-0.1

Python 3.9.12,设置工具 67.6.1

python jupyter-notebook setuptools setup.py python-packaging
1个回答
0
投票

可编辑安装

(-e flag)
和您的目录结构可能存在问题。

首先修改

setup.py
文件,加入
packages
参数

from setuptools import setup, find_packages

setup(
    name="projectmnemonic",
    version="0.1",
    packages=find_packages()
)

然后去projectmnemonic

cd path/to/my-datascience-project/projectmnemonic
然后正确安装你的包
pip install -e .

© www.soinside.com 2019 - 2024. All rights reserved.