talkpython / mastering-pycharm-course

Course demos and handouts for Talk Python's Effective PyCharm course
https://training.talkpython.fm/courses/explore_pycharm/mastering-pycharm-ide
GNU General Public License v2.0
1.13k stars 716 forks source link

Getting 'Cannot use module name 'service.py' in imports' error in the refactoring module #16

Closed swedishmike closed 3 years ago

swedishmike commented 6 years ago

When I try to do the first part of the Large module smell exercise I get the following error:

mpc-4-refactoring-error

The steps I'm trying to do is:

I'm not sure if I'm doing it the wrong way or if it might have something do do with my OS and/or version of PyCharm.

I'm running version 2018.2 on Xubuntu 16.04.

mikeckennedy commented 6 years ago

Hi Mike,

That is weird. I just tried this from scratch on a new project, same version of PyCharm (but on macOS) and it worked fine. Is there already a file named service.py or something installed in the environment that is a package called service?

swedishmike commented 6 years ago

Hi Michael,

I'm a black belt in weird computer behavior... ;)

Thanks for getting back to me - I can't find anything else in the environment but I'll create a new venv, just in case, and see if that helps.

There is of course the empty service.py that's in the directory when I clone the repo from here - I can try and delete that one and try again?

Cheers, Mike

mikeckennedy commented 6 years ago

Yes, that is it probably. Try deleting the service.py file.

On Mon, Oct 8, 2018 at 9:13 AM Mike Eriksson notifications@github.com wrote:

Hi Michael,

I'm a black belt in weird computer behavior... ;)

Thanks for getting back to me - I can't find anything else in the environment but I'll create a new venv, just in case, and see if that helps.

There is of course the empty service.py that's in the directory when I clone the repo from here - I can try and delete that one and try again?

Cheers, Mike

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/talkpython/mastering-pycharm-course/issues/16#issuecomment-427893543, or mute the thread https://github.com/notifications/unsubscribe-auth/AB8Pafhw9InmB7s2wJUuC5NczGqIgAGcks5ui3m7gaJpZM4XLzvW .

swedishmike commented 6 years ago

That didn't resolve it - however, if I marked the 'smelly_podcast' directory as 'sources root' it works.

Many thanks for getting back to me - sometimes a bit of feedback is all that's needed to push me in the right direction. ;)

mikeckennedy commented 6 years ago

You're welcome. It's interesting that it had to do with "sources root". Thanks for digging that one up!

hewettp commented 3 years ago

Same problem here. The refactoring move to service.py is prevented "cannot move module", until the folder containing both files is made a source root. Perhaps it would help to mention this in the video.

mikeckennedy commented 3 years ago

Hi @hewettp You're right about that sources root, depending on how you've opened the project you're editing. I'll add some info about this to the readme.

alfredo-f commented 2 years ago

The error message may be underlying a different issue

PY-55436 Cannot use module name "..." in imports doesn't indicate the problem source

https://youtrack.jetbrains.com/issue/PY-55436/Cannot-use-module-name-in-imports-doesnt-indicate-the-problem-source