After pip install package_name
from my recently uploaded pypi package
It imports python filename directly after installing,
I wanted to use like below
import package_name
or from package_name import python_file
but this doesnt work instead this works
import python_file
even package is installed name is package_name
pypi package name package_name
and
My directory structure is below
setup.py
folder1
In setup.py , i've used package_dir={'': 'folder_1'}
but even import folder_1
or from folder_1 import python_file
didnt worked.
I tried if adding __init__.py
inside folder_1
, it didnt solved.
I've been following Mark Smith - Publish a (Perfect) Python Package on PyPI, which told this way , but any idea what is happening, how can i solve it??
So what you actual did is to tell python that the root folder is folder_1
.
This is not what you want.
You just need to tell that folder_1
(or actually replace it by package_name, see below) is a package and to declare it using:
packages = {'folder1'}
.
Usually, people don't do it but let the function find_packages()
to do the work for them by packages=find_packages()
In addition package folder should contain a __init__.py
.
to conclude you need a folder structure like below and use find_packages()
.
It is OK and even popular choice that the project name and it single main package have the same name.