See error [1;31mModuleNotFoundErrore[0m: No module named 'chromosome_and_gene_positions' ModuleNotFoundError: No module named 'chromosome_and_gene_positions'
Expected behavior
I expect that the file named : gene_reads.md is able to import the modules that require inside the python_modules folder, where I have this code, that works in jupyter notebook:
file_dirname = os.path.dirname(os.path.abspath('__file__'))
sys.path.insert(1,os.path.join(file_dirname,'python_modules'))
from chromosome_and_gene_positions import gene_position
Environment (please complete the following information):
When I print the path of __file__ is the path to python_modules folder where are all the functions I later call. In the normal nortebook it works , but not in the Jupyter Book workflow. Maybe it has to do with the .py files inside /docs ?? I put in the config.yml to exclude_patterns : ["*.py"] but still It does not work .
I have solved it! The point is that it seems that the local build and the web deployment function under different logic on how to interpret the relative path. For the web deployment , the Book takes the same folder structures you have in the project and the output of file_dirname = os.path.dirname('__file__') is exactly the path of the file you are in . For the local build I struggled a bit with this, and what is sometimes a bit annoying is that with the same structure that run in the web it does not build locally and viceversa.
For the modules , the way to call them is from folder_root.subfolder-with-modules.module-a import module-a and it seems also important to add a empty file called __init__.py to the subfolder-with-modules. You can see what I mean here : https://leilaicruz.github.io/SATAY-jupyter-book/gene_reads.html#loading-files
A word of warning though: your approach is mostly a workaround due to the current limitations of jupyter-book. From what I understand, the latest version should make this unnecessary.
This comment. The latest version of one of the packages used in jupyter-book ensures that the files are executed in the same folder to which they belong.
Yes indeed, I think that is the case for web deployment , but did not work for me for the local build.
I installed the new version when I saw the issue reply .
I think this Jupyter Book is a really nice tool for Open science practices , to show , share, and test your code , only using markdown , python and version control with git.