首页 > 解决方案 > 如何使用 pip 安装 python 多包项目?

问题描述

我的项目结构是:

.
├── LICENSE.txt
├── mochgir
│   ├── conf
│   │   ├── consts.py
│   │   ├── font
│   │   │   ├── __init__.py
│   │   │   └── Tahoma.ttf
│   │   └── __init__.py
│   ├── __init__.py
│   └── mochgir.py
├── README.md
└── setup.py

项目代码在mochgir文件夹(包)中。

这是我的 setup.py:

from setuptools import setup

setup(
    name='Mochgir',
    version='0.68',
    license='MIT',
    url='https://www.github.com/javadmokhtari/github',
    description='Translate and Analyze docx documents',
    author='Javad Mokhtari Koushyar',
    packages=(
        'mochgir',
        'mochgir.conf',
        'mochgir.conf.font'
    ),
    include_package_data=True,
    zip_safe=False,
    python_requires='>=3.0',
    install_requires=[
        'requests==2.19.1',
        'python-docx==0.8.6',
        'google==2.0.1',
        'reportlab==3.4.0'
    ]
)

我为 pip 打包它所做的工作:

root@me:~/mm# python3 setup.py sdist bdist_wheel
root@me:~/mm# twine upload --repository-url https://test.pypi.org/legacy/ dist/*
root@me:~/mm# twine upload dist/*

到目前为止一切正常。但安装后我不能像这样使用我的包:

from mochgir import Translate
from mochgir import Analyze

from conf.consts import *

我唯一能做的就是:

import mochgir

甚至上面的代码也不行,它只是一个模块,里面没有我的任何代码。

那么,怎么了?

标签: pythonpippython-packaging

解决方案


推荐阅读