Skip to content

ModuleNotFoundError: No module named 'pypi_org' #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sanders41 opened this issue Jul 7, 2019 · 2 comments
Closed

ModuleNotFoundError: No module named 'pypi_org' #1

sanders41 opened this issue Jul 7, 2019 · 2 comments

Comments

@sanders41
Copy link

I'm in ch06_routing and trying to setup the blueprints. register_blueprints is throwing the error:

ModuleNotFoundError: No module named 'pypi_org' all of the imports.

For example from pypi_org.views import home_views and from pypi_org.views import package_views both cause the error. I do have a views directory inside of the pypi_org directory, and app.py is at the root of pypi_org.

Inside of the views directory the import of services does not cause this error (import pypi_org.services.package_service as package_service runs with no error).

I can't figure out why I am getting the error in the app.py file.

@sanders41
Copy link
Author

I figured it out. I needed to add the lines:

folder = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, folder)

In the video from the course things were working without those two lines. Is it a PyCharm thing that made it work? I'm using VSCode so maybe that is why I had an issue before adding this?

@mikeckennedy
Copy link
Member

mikeckennedy commented Jul 8, 2019

Hi @sanders41 Glad you got that line in there. Yes, this is working because PyCharm patches things up to work as if the project is a package (mostly). Whereas VS code and others just run the Python file. Basically, look at this part of the config:

Screen Shot 2019-07-08 at 10 18 25 AM

[From the run configuration]

See the bit about adding content paths as source roots? That's happening automatically there but not when you run without PyCharm, hence the lines you added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants