[Python] Why can't find imported editable python package?

Discussão em 'Python' iniciado por Stack, Outubro 5, 2024.

  1. Stack

    Stack Membro Participativo

    1. The dir1 directory structure:

    dir1/
    |-- helloworld/
    |-- __init__.py
    |-- hello.py
    |-- setup.py
    |-- venv/ #The dir1 virtual environment

    1. The dir2 directory structure:

    dir2/
    |-- app2.py
    |-- venv/ #The dir2 virtual environment


    # hello.py
    def say_hello():
    return "Hello, World!"


    # setup.py
    from setuptools import setup, find_packages

    setup(
    name='helloworld',
    version='0.1',
    packages=find_packages(),
    )

    1. Activate dir2 venv

    C:\Users\TC\temp\editable\dir2>venv\Scripts\activate
    (venv) C:\Users\TC\temp\editable\dir2>

    1. Install helloworld package to the dir2 venv in editable mode.

    (venv) C:\Users\TC\temp\editable\dir2>pip install -e C:\Users\TC\temp\editable\dir1

    1. Import helloworld package from app2.py

    # app2.py
    from helloworld.hello import say_hello

    print(say_hello())

    1. Run app2.py

    python app2.py


    Now here is the problem. helloworld package is not found from app2.py. However, pip list does show that the helloworld package has been installed. Using VS Code, there is a yellow squiggly line underneath helloword.hello, which indicates that package not found.

    This is a very simple setup to test the editable installation of a python package. I wonder the error is producible. Or this is a bug! OS is windows.

    Please let me know if you get the same error or you will be able to get it to work.

    Any help will be greatly appreciated.

    Note:

    You need to pip install setuptools in dir1 venv.

    Continue reading...

Compartilhe esta Página