【问题标题】:Local Pip install not able to import any classes within the package本地 Pip 安装无法导入包中的任何类
【发布时间】:2017-11-25 04:49:27
【问题描述】:

我有一个从

构建的 python 包
python setup.py sdist

包名是:yify

我是用这个安装的

pip3 install . 

之后,当我打开 python3 解释器和 import Yify 时,它会成功导入,但它似乎不包含 dist_packages/Yify 目录中的主要 python 文件。

这是文件夹结构:-

├── dist
│   └── Yify-1.0.tar.gz
├── get-pip.py
├── LICENSE
├── README.rst
├── requirements.txt
├── setup.cfg
├── setup.py
├── Yify
│   ├── __init__.py
│   ├── venv
|   ├── Yify.py

Yify.py 包含 yify 类。 当我这样做时

import Yify
Yify.yify()

它给了我“yify”未找到错误! .

如何解决?

这里是 setup.py 的内容:-

import platform
from setuptools import setup

install_requires = ['bs4' , 'urllib3' ]


setup(
    name='Yify',
    packages = ['Yify'] ,
    version = 'v1.0',
    description = '''
    This Module is used to get the Top seeded torrents at any given time and get the entire movie details and ratings . 
    Its also useful to search for any movie using different parameters and obtain their magnet link or torrent file of any prefered quality.
''' ,
    author = 'Natesh M Bhat' ,
    url = 'https://github.com/nateshmbhat/Yify-Python',
    author_email = 'nateshmbhatofficial@gmail.com' ,
    # download_url = 'https://github.com/nateshmbhat/pyttsx3/archive/v2.6.tar.gz',
    keywords=['yify','torrent-python' , 'movie-torrent' , 'torrent' , 'pyyify' , 'Yify' , 'yify torrent' , 'yify download' , 'download yify' , 'yifyer'  , 'yifypy' , 'torrent download' , 'movie torrent' , 'movie downloader', 'movie finder'],
    classifiers = [] ,
    install_requires=install_requires
)

当我直接进入 python3.6 distpackages/Yify 文件夹并从那里执行 python3 时。一切正常。

还有 dir(Yify) 只返回以下字段

dir(Yify)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']

【问题讨论】:

  • 你不应该打电话给setup.py 请问你为什么不直接打电话pip install yify
  • 它不在pypi存储库中,它是我本地的python库。要先上传到 Pip,我在上传之前对其进行了测试。
  • 尝试使用 pip install -e "您在本地下载的路径"
  • 尝试使用 pip install -e "您在本地下载的路径"
  • 你试过了。同样的事情。

标签: python deployment pip setuptools pypi


【解决方案1】:
  1. __init__. 必须称为__init__.py

  2. 当您执行import Yify 时,您只导入Yify/__init__.py,而不是Yify/Yify.py,除非它在__init__.py 中导入。

  3. 要修复您的导入,请执行以下操作:from Yify import Yify。这样你就可以真正导入Yify/Yify.py

【讨论】:

    猜你喜欢
    • 2021-06-15
    • 2023-04-09
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 2019-01-16
    • 1970-01-01
    • 1970-01-01
    • 2018-08-04
    相关资源
    最近更新 更多