【发布时间】:2021-10-21 09:09:22
【问题描述】:
每次我尝试启动我的笔记本时,我都会收到以下错误。 让我们指定我是该项目的新员工,并且在我加入团队之前创建了文件 config.py。
请问有人知道怎么解决吗?
实际完成的代码是
Requirements.txt
psycopg2==2.7.3.2.
SQLAlchemy==1.2.2
pandas==0.21.0
docker==3.3.0
python-json-logger
sshtunnel==0.1.4
jupyter
jupytext==1.2
geopy==2.2.0
错误详情
~/SG/notebooks/config.py in <module>
1 # Using jupytext
----> 2 c.NotebookApp.contents_manager_class = "jupytext.TextFileContentsManager"
3 c.ContentsManager.default_jupytext_formats = "ipynb,py"
NameError: name 'c' is not defined
代码
笔记本中导致错误的行是
from src.util.connect_postgres import postgres_connexion
文件connect_postgres的内容
from sqlalchemy import create_engine
from config.util.database import TARGET_TEST_HOST, TARGET_PROD_HOST, \
TARGET_TEST_DB, TARGET_PROD_DB, TARGET_TEST_USER, TARGET_PROD_USER, SG_PROD_USER, SG_PROD_HOST
from config.secrets.passwords import TARGET_PROD_PWD, TARGET_TEST_PWD, SG_PROD_PWD
from sshtunnel import SSHTunnelForwarder
import psycopg2
def _create_engine_psg(user, db, host, port, pwd):
""" Returns a connection object to PostgreSQL """
url = build_postgres_url(db, host, port, pwd, user)
return create_engine(url, client_encoding='utf8')
def build_postgres_url(db, host, port, pwd, user):
url = 'postgresql://{}:{}@{}:{}/{}'.format(user, pwd, host, port, db)
return url
def postgres_connexion(env):
if env == 'prod':
return create_engine_psg_with_tunnel_ssh(TARGET_PROD_DB,
TARGET_PROD_USER, TARGET_PROD_PWD, SG_PROD_PWD,
SG_PROD_USER,
SG_PROD_HOST, TARGET_PROD_HOST)
else:
raise ValueError("'env' parameter must be 'prod'.")
config.py
c.NotebookApp.contents_manager_class = "jupytext.TextFileContentsManager"
c.ContentsManager.default_jupytext_formats = "ipynb,py"
我红色表示我可以生成文件然后对其进行编辑。
当我尝试创建 jupyter_notebook_config 时,它始终位于我的个人 marczhr 目录中
/Users/marczhr/.jupyter/jupyter_notebook_config.py
但我想完成一些我可以在 git 上推动的事情。
希望我清楚^^
谢谢,
【问题讨论】:
-
您帖子中的许多代码 sn-ps 并不能真正帮助回答问题。这里唯一重要的是
config.py,其中c被定义/实例化。如果您可以发布您的config.py,那对我们来说会更容易合作。 -
config.py 已经存在于我的原始帖子中。比你^^ @onlyphantom
-
你是如何启动笔记本的?
-
“但我想完成一些我可以在 git 上推送的事情。”:我建议不要这样做:在这种情况下,配置文件是系统或用户特定的,而不是项目特定的。如果有一些配置应该应用于项目,您应该找到另一种类型的配置文件,或者更好的是,以编程方式将其添加到相关代码中。
-
从以上所有情况来看,项目/团队似乎真的需要让一个了解他们的 Python 知识并让项目恢复最新的人加入。这将比在互联网上尝试和询问要好得多,因为人们对项目的了解有限。
标签: python pandas jupyter-notebook