Python pip 不会下载/安装自制包的源代码。

huangapple go评论68阅读模式
英文:

Python pip doesnt download/install source code from self-made package

问题

I've translated the non-code parts of your text:

最近,我一直在为学习目的而开发一个Python包。我将这个包命名为Logmaster,正如其名称所示,它是一个日志记录库。当我安装该包(pip install logmaster)时,只会下载dist-infos(在这种情况下为logmaster-1.0.1.dist-infos),而不会下载实际的源代码。

项目结构:

Logmaster
├── LICENSE
├── README.md
├── src
│   ├── __init__.py
│   └── logger.py
├── pyproject.toml
└── setup.cfg

我尝试解压构建的源代码(logmaster-0.1.0)以查看是否包含在内,事实上是包含在内的,但尝试修改__init__.py文件的内容,从from .logger import *修改为from . import *,但未能成功。

所有代码都在GitHub上。

包在PyPi上。

英文:

Latelly, I've been worked on a Python Package, for learning purposes. I called this package Logmaster and, as it suggests, is a logging library. When I install the package (pip install logmaster), Only the dist-infos (in this case logmaster-1.0.1.dist-infos) are downloaded, not the actual source code.

Project structure:

Logmaster
├── LICENSE
├── README.md
├── src
│   ├── __init__.py
│   └── logger.py
├── pyproject.toml
└── setup.cfg

I tried to decompress the source code of the build (logmaster-0.1.0) to see if it was included, which it was, and to modify the content of the __init__.py file from from .logger import * to from . import *, and it didn't worked.

All the code is on github

Package on PyPi

答案1

得分: 0

A simpler solution, use a setup.py. (I changed the directory structure slightly):

$ git clone https://github.com/W1L7dev/Logmaster.git
$ cd Logmaster/
$ mv src/ logmaster/
$ echo "" > logmaster/__init__.py
$ rm pyproject.toml
$ rm setup.cfg
$ cat setup.py
from setuptools import setup

setup(
    name='logmaster',
    version='0.1.0',
    description='A simple logging library for Python',
    url='https://github.com/W1L7dev/logmaster',
    author='W1L7dev',
    author_email='w1l7dev@gmail.com',
    license='MIT',
    packages=['logmaster'],
    install_requires=[],
    classifiers=[
        'Programming Language :: Python :: 3.6',
    ],
)

With this it works as expected:

$ pip install -e .
Successfully installed logmaster-0.1.0
$ python
>>> from logmaster.logger import Logger
>>> Logger
<class 'logmaster.logger.Logger'>
>>> exit()
$ python3 -m build
Successfully built logmaster-0.1.0.tar.gz and logmaster-0.1.0-py3-none-any.whl
$ ls dist/
logmaster-0.1.0-py3-none-any.whl  logmaster-0.1.0.tar.gz
英文:

A simpler solution, use a setup.py. (I changed the directory structure slightly):

$ git clone https://github.com/W1L7dev/Logmaster.git
$ cd Logmaster/
$ mv src/ logmaster/
$ echo &quot;&quot; &gt; logmaster/__init__.py
$ rm pyproject.toml
$ rm setup.cfg
$ cat setup.py
from setuptools import setup

setup(
    name=&#39;logmaster&#39;,
    version=&#39;0.1.0&#39;,
    description=&#39;A simple logging library for Python&#39;,
    url=&#39;https://github.com/W1L7dev/logmaster&#39;,
    author=&#39;W1L7dev&#39;,
    author_email=&#39;w1l7dev@gmail.com&#39;,
    license=&#39;MIT&#39;,
    packages=[&#39;logmaster&#39;],
    install_requires=[],
    classifiers=[
        &#39;Programming Language :: Python :: 3.6&#39;,
    ],
)

With this it works as expected:

$ pip install -e .
Successfully installed logmaster-0.1.0
$ python
&gt;&gt;&gt; from logmaster.logger import Logger
&gt;&gt;&gt; Logger
&lt;class &#39;logmaster.logger.Logger&#39;&gt;
&gt;&gt;&gt; exit()
$ python3 -m build
Successfully built logmaster-0.1.0.tar.gz and logmaster-0.1.0-py3-none-any.whl
$ ls dist/
logmaster-0.1.0-py3-none-any.whl  logmaster-0.1.0.tar.gz

huangapple
  • 本文由 发表于 2023年5月14日 04:58:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76244851.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定