Problem
I have read this post, which provides a way to permanently avoid the sys.path
hack when importing names between sibling directories. However, I followed the procedures listed in that post but found that I could not import installed package (i.e. test
).
The following are things I have already done
- Step1: create a project that looks like following. Both
__init__.py
are empty.
test
├── __init__.py
├── setup.py
├── subfolder1
│ ├── __init__.py
│ ├── program1.py
├── subfolder2
│ ├── __init__.py
│ └── program2.py
# setup.py
from setuptools import setup, find_packages
setup(name="test", version="0.1", packages=find_packages())
# program1
def func1():
print("I am from func1 in subfolder1/func1")
# program2
from test.subfolder1 import program1
program1.func1()
- Step2. create virtual environment in project root directory (i.e.
test
directory)conda create -n test --clone base
- launch a new terminal and
conda activate test
pip install -e .
conda list
and I see the following, which means mytest
project is indeed installed in the virtual environment
...
test 0.1 dev_0 <develop>
...
- Step3: go to the
subfolder2
andpython program2.py
, but unexpectedly it returned
ModuleNotFoundError: No module named 'test.subfolder1'
The issue is I think test
should be available as long as I am in virtual environment. However, it does not seem to be the case here.
Could some one help me? Thank you in advance!