Jun-27-2021, 11:36 PM
Hi there, I have just created my first package and I'm testing it out before I upload it to pypi. As I was testing it I ran into an issue, fixed it, but didn't understand how it fixes it. I'm hoping to get some help understanding what the problem was.
Here is the source code: https://gitlab.com/cuppajoeman/numuse
I am running python 3.9 - my os is linux
First I installed my package from testpypi in a venv and imported everything from one of the modules at the top of a file graph.py like this:
I read around a little bit, and it seems like in general relative imports are more fragile then absolute ones: https://softwareengineering.stackexchang...-in-python
So I'm not 100% satified with the solution
If someone can explain why these errors occured, and what a proper fix might be, please let me know.
Best,
C
Here is the source code: https://gitlab.com/cuppajoeman/numuse
I am running python 3.9 - my os is linux
First I installed my package from testpypi in a venv and imported everything from one of the modules at the top of a file graph.py like this:
from numuse.converters import *and after running python graph.py - I get the following error:
py File "/home/ccn/music/graph_music/graph.py", line 4, in <module> from numuse.converters import *z File "/home/ccn/music/graph_music/numuse-venv/lib/python3.9/site-packages/numuse/converters.py", line 1, in <module> from tools import ranged_modulus_operator ModuleNotFoundError: No module named 'tools'So I went and took a look at the file giving the error:
(numuse-venv) [ccn@sy337b4 graph_music]$ head numuse-venv/lib/python3.9/site-packages/numuse/converters.py from tools import ranged_modulus_operator import re import pprint from typing import Tuple, Set, List, Optional from fractions import Fraction from notation import RootedIntervalCollection, NoteCollectionwhere I was able to see that the import from tools must be failing, which I found odd because in that very same folder we have tools.py:
(numuse-venv) [ccn@sy337b4 graph_music]$ ls numuse-venv/lib/python3.9/site-packages/numuse/ constants.py converters.py __init__.py musical_system.py music.py notation.py __pycache__ tools.pyI asked someone and they recommended adding a dot in front of the module, so that I would instead have the line
from .tools import ranged_modulus_operator
. This fixed that error - and I had to do that in a few different locations before everything ran just fine. I read around a little bit, and it seems like in general relative imports are more fragile then absolute ones: https://softwareengineering.stackexchang...-in-python
So I'm not 100% satified with the solution
If someone can explain why these errors occured, and what a proper fix might be, please let me know.
Best,
C