'Unable to import package installed in develop mode

Directory structure:

root/
-> setup.py
-> src/
-> -> package1/
-> -> -> __init__.py

Content of setup.py

from setuptools import setup

setup(
    name='ptest',
    version='1.0',
    packages=['package1'],
    package_dir={'package1': 'src/package1'}
)

INSTALL

when I install the package using python3 setup.py install

I am able to import the package1 using python3 -c 'import package1'

I could see file ptest-1.0-py3.7.egg added into site-packages and line ./ptest-1.0-py3.7.egg added into file site-packages/easy-install.pth.

On unziping ptest-1.0-py3.7.egg contents are:

  inflating: EGG-INFO/PKG-INFO       
  inflating: EGG-INFO/SOURCES.txt    
  inflating: EGG-INFO/dependency_links.txt  
  inflating: EGG-INFO/top_level.txt  
  inflating: EGG-INFO/zip-safe       
  inflating: package1/__init__.py    
  inflating: package1/__pycache__/__init__.cpython-37.pyc  

So I am able to access package1, which is normal according to me.

DEVELOP (Issue lies here)

But when I install the package using python3 setup.py develop or even when I use pip3 install -e .

I am not able to import the package1 using python3 -c 'import package1'

I could see line /path/to/root added to file site-packages/easy-install.pth and another file ptest.egg-link in site-packages, contents of this file are:

/path/to/root
.

Also I could see /path/to/root is being added to the sys.path.

Here is my question: I want to make setup.py such a way that when I run it in develop mode, I should be able to import package1 some way that /path/to/root/src gets added to sys.path using setup.py.

Let me know if I am doing something wrong regarding understanding of setup.py.

NOTE: site-packages folder is inside virtual environment folder. I am using virtual environment for this.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source