英文:
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 "" > 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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论