Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Calling pip package files from within pip package? (`No module named 'src.snnalgorithms'`)

Whilst in some_other_package, I am importing files from the snnalgorithms pip package. I received the error:
No module named 'src.snnalgorithms'. This is a valid error because that src.snnalgorithms file does not exist in the some_other_package project from which I was calling the pip package.

As a solution, I can make all the imports in the snn.algorithms pip package, relative to itself. Instead of:

from src.snnalgorithms.population.DUMMY import DUMMY

One could write:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

from snnalgorithms.population.DUMMY import DUMMY

However, that implies that each time I want to run the code to briefly verify a minor change, or run the tests after a change, I will have to:

  1. Upload the changes into the pip package.
  2. Re-install the pip package locally to reflect the changes.

This significantly slows down development. Hence I was wondering are there more efficient solutions for this?

>Solution :

You can use editable mode for development mode

pip install -e .  # Install package locally 

From pip documentation:

Editable installs allow you to install your project without copying any files. Instead, the files in the development directory are added to Python’s import path. This approach is well suited for development and is also known as a “development installation”.

With an editable install, you only need to perform a re-installation if you change the project metadata (eg: version, what scripts need to be generated etc). You will still need to run build commands when you need to perform a compilation for non-Python code in the project (eg: C extensions).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading