mirror of
https://github.com/initialcommit-com/git-sim.git
synced 2026-04-27 03:25:53 +03:00
[GH-ISSUE #18] ModuleNotFoundError when executing source code locally, if "git_sim." prefix isn't removed #13
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/git-sim#13
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @initialcommit-io on GitHub (Jan 25, 2023).
Original GitHub issue: https://github.com/initialcommit-com/git-sim/issues/18
@paketb0te I think maybe you can help me with this since I haven't had too much time to research it.
Basically, for local testing of Git-Sim I like to directly run the
__main__.pyfile with python like this:But the problem is since it's not running as a package I end up getting errors like:
ModuleNotFoundError: No module named 'git_sim.git_sim_add'; 'git_sim' is not a packageI can get around this by removing the package prefix
git_sim.in all the imports, but its very annoying because I need to remember to stash those changes before building the code for release, and I need to make sure not to commit that by accident.Do you have any thoughts on how I can test locally without having to mess with the imports like that?
@cclauss commented on GitHub (Jan 25, 2023):
Did you try installing with https://pypa.github.io/pipx instead of
pip? What operating system are you using?@paketb0te commented on GitHub (Jan 25, 2023):
@initialcommit-io yeah I think the whole imports / packages / modules stuff is one of the more confusing parts of python, I find myself trying to make sense of it very often 😅
I tried running the file directly and see the same behavior you described.
I think I found the issue in our case though: We have a file
git_sim.py(which for python is a module) inside the directorygit_sim(which for python is a package:So what I think happens, is that python gets confused that there is a module and a package with the same name.
For me it seems to work in either case after moving the contents of
git_sim.pyinto__main__.pyand deleting it, see my branch fix_ModuleNotFoundError.@paketb0te commented on GitHub (Jan 25, 2023):
We could of course also just rename the file
git_sim.py,git_sim_foo.pyworked for me (import git_sim.git_sim_foo as gsin the__main__.pyfile) 😆@initialcommit-io commented on GitHub (Jan 25, 2023):
I do prefer to keep
GitSimclass in a separate module than__main__.py.Hmm, so I renamed
git_sim.pytogit_sim_scene.py, and changed the import in__main__.pytoimport git_sim.git_sim_scene as gs.But when I run
python __main__.py statusor something, I still get:Does this work for you?
@paketb0te commented on GitHub (Jan 25, 2023):
Yeah, that works for me 🤔
(updated my branch accordingly)
@abhijitnathwani commented on GitHub (Jan 26, 2023):
Hi guys,
To avoid messing the imports, I'd suggest to install from source as development mode to try locally.
To test this, please uninstall any versions of git-sim you may have installed,
cd path/to/repopython setup.py developThis will install all the necessary dependencies listed in the package and install in developer mode. Meaning, it will always use the source to serve the commands. You can edit the source and it will be reflected immediately. I have opened a PR to update the
CONTRIBUTING.mdwith these steps. If things work, we can close this issue.@initialcommit-io commented on GitHub (Jan 26, 2023):
This was fixed with the help of @abhijitnathwani and @cclauss. See linked PR for details.
Thank you both!