简体   繁体   English

无法让python导入其他文件夹中的nba_py

[英]Can't get python to import nba_py that's in a different folder

I am using Python2.7 and Google App Engine for this project. 我正在为此项目使用Python2.7和Google App Engine。 I am a huge NBA fan and I want to use nba_py api to retrieve additional information to be display on my website but can't seem to import it correctly. 我是NBA的忠实粉丝,我想使用nba_py api检索要显示在我的网站上的其他信息,但似乎无法正确导入。 I am trying to import it inside my blogfront.py but when I refresh the browser I get an error. 我试图将其导入我的blogfront.py中,但是刷新浏览器时出现错误。 Here's my directory structure. 这是我的目录结构。

multi-user-blog
      - libraries
            - nba_py
                 -nba_py
                     - __init__.py
      - handlers
           -blogfront.py
           - __init__.py
      - mainblog.py

Here's my blogfront.py 这是我的blogfront.py

from bloghandler import BlogHandler
from models.post import Post

from libraries.nba_py import nba_py


# Render Home Page
class BlogFront(BlogHandler):
    def get(self):
        # type: () -> object
        posts = Post.all().order('-created')
        title = "Blog/Scores"
        standing = get_standing()
        self.render('front.html', posts=posts, title=title)


    def get_standing():
        scoreboard = nba_py.Scoreboard()
        print scoreboard.west_conf_standings_by_day()

Here's my mainblog.py 这是我的mainblog.py

import sys
import os
import re
import random
import hashlib
import hmac
import webapp2
import jinja2
import time


from handlers.bloghandler import BlogHandler
from handlers.blogfront import BlogFront
from handlers.deletecomment import DeleteComment
from handlers.deletepost import DeletePost
from handlers.likepost import Likes
from handlers.login import Login
from handlers.logout import Logout
from handlers.addcomment import AddComment
from handlers.newpost import NewPost
from handlers.postpage import PostPage
from handlers.signup import Signup
from handlers.signup import Register
from handlers.editcomment import EditComment
from handlers.editpost import EditPost


from models.comment import Comment
from models.user import User
from models.post import Post

from helpers import *

from string import letters
from google.appengine.ext import db


app = webapp2.WSGIApplication([('/', BlogFront),
                               ('/blog/?', BlogFront),
                               ('/postpage/([0-9]+)', PostPage),
                               ('/edit/([0-9]+)', EditPost),
                               ('/delete/([0-9]+)', DeletePost),
                               ('/addcomment/([0-9]+)', AddComment),
                               ('/blog/([0-9]+)/editcomment/([0-9]+)',
                                EditComment),
                               ('/blog/([0-9]+)/deletecomment/([0-9]+)',
                                DeleteComment),
                               ('/blog/like/([0-9]+)', Likes),
                               ('/blog/newpost', NewPost),
                               ('/signup', Register),
                               ('/login', Login),
                               ('/logout', Logout),
                               ],
                              debug=True)

The error is: ImportError: No module named libraries.nba_py 错误是:ImportError:没有名为libraries.nba_py的模块

How did you install nba_py ? 您如何安装nba_py

If you install it with pip, you can just do import nba_py . 如果使用pip进行安装,则只需import nba_py There is no need for your libraries structure. 不需要您的libraries结构。

Do you have a __init__.py at every step in the directory chain? 您在目录链的每个步骤中都有__init__.py吗? That always gets me 那总是让我

multi-user-blog
      - libraries
            - __init__.py       <-------
            - nba_py
                 - __init__.py  <-------
                 -nba_py
                     - __init__.py

From what you described, it's not clear whether you've followed the advice in https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27 and installed nba_py into your project using using pip install -t , and also added an appengine_config.py to do a vendor.add() . 根据您的描述,目前尚不清楚您是否遵循https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27中的建议,并使用以下命令将nba_py安装到项目中使用pip install -t ,还添加了一个appengine_config.py来进行vendor.add() Without those steps, your app will be sad. 没有这些步骤,您的应用程序将很难过。

Also, since nba_py wants to use pandas, you'll want to also pip install -t it, and since pandas wants numpy, you'll need the following in your app.yaml : 另外,由于nba_py要使用pandas,因此您还希望pip install -t它,并且由于pandas需要numpy,因此在app.yaml需要以下内容:

libraries:
- name: numpy
  version: "1.6.1"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM