Search code examples
pythondeploymentpipsetuptoolspypi

Local Pip install not able to import any classes within the package


I have a python package which I built from

python setup.py sdist

The package name is : Yify

I installed this using

pip3 install . 

After this when I open the python3 interpreter and import Yify , it imports successfully but it doesn't seem to include the main python file inside the dist_packages/Yify directory .

Here is the folder structure :-

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

The Yify.py contains yify class . When i do

import Yify
Yify.yify()

It gives me 'yify' not found error ! .

hOW TO fix it ?

Here is the setup.py contents:-

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 = '[email protected]' ,
    # 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
)

Also When I directly go into the python3.6 distpackages/Yify folder and execute python3 from there. Everything works fine .

Also dir(Yify) return only the below fields

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

Solution

    1. __init__. must be called __init__.py.

    2. When you do import Yify you only import Yify/__init__.py, not Yify/Yify.py unless it's imported in __init__.py.

    3. To fix you import do: from Yify import Yify. That way you really import Yify/Yify.py.