Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.1k views
in Technique[技术] by (71.8m points)

python - Why can't I import the page.py module in the PageObjects directory?

I am following the flaskr tutorial so my code is similar to (https://flask.palletsprojects.com/en/1.1.x/tutorial/). I am also following the Selenium PageObjects tutorial (https://selenium-python.readthedocs.io/page-objects.html).

flask_tutorial
├── flaskr
│?? ├── auth.py
│?? ├── company_database.py
│?? ├── __init__.py
│?? ├── PageObjects
│?? │?? ├── element.py
│?? │?? ├── geckodriver.log
│?? │?? ├── locators.py
│?? │?? ├── main.py
│?? │?? ├── page.py
│?? │?? └── README.ME
│?? ├── schema.sql
│?? ├── static
│?? │?? └── style.css
│?? └── templates
│??     ├── auth
│??     ├── base.html
│??     └── index.html
├── instance
│?? └── flask.sqlite
└── setup.py

At the beginning I am importing my PageObject main.py file; PythonOrgSearch class in flaskr/auth.py.

from flask import (
    Blueprint, flash, g, redirect, render_template, request, session, url_for
)

from .PageObjects.main import PythonOrgSearch

The PythonOrgSearch class imports page module.

import unittest
from selenium import webdriver
import sys

import page

class PythonOrgSearch(unittest.TestCase):

Why can't it import the page.py module?

Error

Traceback (most recent call last):
  File "/home/nbosio1001/anaconda3/lib/python3.7/site-packages/flask/cli.py", line 83, in find_best_app
    app = call_factory(script_info, app_factory)
  File "/home/nbosio1001/anaconda3/lib/python3.7/site-packages/flask/cli.py", line 119, in call_factory
    return app_factory()
  File "/home/nbosio1001/Documents/python/Fundamental_Analysis/app/flask_tutorial/flaskr/__init__.py", line 41, in create_app
    from . import auth
  File "/home/nbosio1001/Documents/python/Fundamental_Analysis/app/flask_tutorial/flaskr/auth.py", line 7, in <module>
    from .PageObjects.main import PythonOrgSearch
  File "/home/nbosio1001/Documents/python/Fundamental_Analysis/app/flask_tutorial/flaskr/PageObjects/main.py", line 5, in <module>
    import page
ModuleNotFoundError: No module named 'page'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You may need an __init__.py file in the PageObjects directory.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...