joeyaurel / python-gedcom

Python module for parsing, analyzing, and manipulating GEDCOM files
https://gedcom.joeyaurel.dev
GNU General Public License v2.0
154 stars 39 forks source link

Can't install? #26

Closed jamestho closed 4 years ago

jamestho commented 5 years ago

Hi,

This looks like a cool piece of code - so, first of all, thank you :)

I'm probably doing something wrong, but I installed python-gedcom as per instructions, ie. pip3 install python-Gedcom. It shows as being installed correctly. When I use your example code, I receive the following error message:

Traceback (most recent call last):
  File "Gedcom.py", line 3, in <module>
    from gedcom.element.individual import IndividualElement
  File "/home/james/Coding/gedcom/gedcom.py", line 3, in <module>
    from gedcom.element.individual import IndividualElement
ModuleNotFoundError: No module named 'gedcom.element'; 'gedcom' is not a package

I also commented out the: '#from gedcom.element.individual import IndividualElement', to use the strict parser as the source gedcom is an ancestry gedcom 5.5 file, and I receive the same message.

useful stats: python version 3.7.3 Arch Linux ARM aarch64 (Odroid N2 SBC) I'm quite new to python programming!

Any thoughts/advice would be gratefully received - thank you!

joeyaurel commented 5 years ago

Hey there :) Could you upload your whole code that triggers this error?

jamestho commented 5 years ago

hi :) Thanks for your quick response - all my code is in my repo: https://gitlab.com/thornbej/gedcom-python have a look at gedcom.py Many thanks!

joeyaurel commented 5 years ago

No problem :) One issue with your code is that you are using the IndividualElement class but not importing it (since you've commented out the #from gedcom.element.individual import IndividualElement on line 3).

https://gitlab.com/thornbej/gedcom-python/blob/master/gedcom.py#L21

The usage of the IndividualElement class has nothing to do with strict parsing. It's there to allow for extra functionality if the current element is an actual IndividualElement and not just an Element.

Strict parsing is described here. :)

jamestho commented 5 years ago

I have just uncommented the from gedcom.element.individual import IndividualElementon line 3, and tried running it again, and I receive the same error message.

[james@minfilia:~/Coding/gedcom]$ python gedcom.py 
Traceback (most recent call last):
  File "gedcom.py", line 3, in <module>
    from gedcom.element.individual import IndividualElement
  File "/home/james/Coding/gedcom/gedcom.py", line 3, in <module>
    from gedcom.element.individual import IndividualElement
ModuleNotFoundError: No module named 'gedcom.element'; 'gedcom' is not a package

I'll have a look at the Strict Parsing link that you sent to me. Thanks for your help so far! :)

joeyaurel commented 5 years ago

And it seems you are using the Gedcom.py file via your terminal? Are you using Virtualenv or the like? I hardly recommend using pyenv to manage Python versions and environments in which you can run and test your code.

jamestho commented 5 years ago

Yes, I was running it directly from the CLI! I wasn't running it in virtualenv, but I just installed it, activated my environment, and redownloaded python-gedcom and I continue to receive the same error. my virtualenv is called 'project-gedcom'

(project-gedcom) [james@minfilia:~/Coding/gedcom/project-gedcom]$ python gedcom.py 
Traceback (most recent call last):
  File "gedcom.py", line 3, in <module>
    from gedcom.element.individual import IndividualElement
  File "/home/james/Coding/gedcom/project-gedcom/gedcom.py", line 3, in <module>
    from gedcom.element.individual import IndividualElement
ModuleNotFoundError: No module named 'gedcom.element'; 'gedcom' is not a package

Should I try pyenv too do you think?

joeyaurel commented 5 years ago

Hmmm seems like it can't find any modules which is weird. Tried installing it too (without pyenv or a Virtualenv) and copied your code and files and ran into the same error. I will have a look on that later this day or week if you're fine with that :)

jamestho commented 5 years ago

totally fine with that! There's no immediate rush! Thank you! :)

KeithPetro commented 5 years ago

Would you be able to run help("modules") in Python. It almost seems like pip is installing it for a different python installation. The result of that command should include "gedcom" somewhere in it.

IvicaPizent commented 4 years ago

I know that this is a late response, but I will still post the solution.

Your file is called gedcom.py. When you try to do from gedcom.element.individual import IndividualElement, Python will first look for a package named gedcom in your project. Since your file is called gedcom.py, Python thinks that is the right package to import. Fix: rename your gedcom.py to main.py or something else. Hope it helps!

joeyaurel commented 4 years ago

@IvicaPizent Thank you! Makes sense.

I just added a "Common problems" section to the README.md file of the project, describing this problem and how to avoid it.

Closing this issue now.