首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ubuntu终端打开Python而不是运行Python文件

Ubuntu终端打开Python而不是运行Python文件
EN

Stack Overflow用户
提问于 2022-04-29 12:06:59
回答 1查看 44关注 0票数 1

我试图使用python3 index.py从Ubuntu终端运行python脚本,但是Ubuntu只是打开Python终端,而不是运行实际的脚本。这种行为仅在最近几天开始,在此之前,代码按预期运行。

这只发生在一个特定的文件夹中,我相信它与文件夹的虚拟环境有关(使用venv创建)。当虚拟环境未被激活时,python3 index.py将尝试运行该文件,而我将收到一个ModuleNotFound错误。

导致此问题的文件夹包含创建仪表板web应用程序的文件,这些文件已被放入Docker容器中,因此我不确定这是否与其有关。

机器: Windows 11

Python: 3.8.10

Ubuntu: 20.04

问题文件夹的内容:

代码语言:javascript
复制
|apps
  -competitors.py
  -data.py
  -functions.py
  -media_posts.py
  -overview.py
  -post_performance.py
  -text.py
|assets
|env
-.env
-app.py
-Dockerfile
-index.py
-requirements.txt

index.py文件的内容:

代码语言:javascript
复制
import dash_html_components as html
import dash_core_components as dcc
import dash_bootstrap_components as dbc
from dash.dependencies import Input, Output
from app import app, server
from apps import overview, media_posts, competitors, post_performance, overview, text


header = dbc.Container([
    dbc.Row([
        dbc.Col(dcc.Link(html.Img(src="assets/nomadpursuit3.png"), href="https://www.instagram.com/nomadpursuit/"),
                className="col-4"),
        dbc.Col(html.H1("Instagram Performance"), className="col-6 col-center"),
        dbc.Col(html.P(), className="col-2")
    ], className="col-center")
])

# create the page layout using the previously created sidebar
app.layout = html.Div([
    dcc.Location(id="url", refresh=False),
    header,
    html.Div(id="page-content")
])


# callback to load the correct page content
@app.callback(Output("page-content", "children"),
              Input("url", "pathname"))
def create_page_content(pathname):
    if pathname == "/overview":
        return overview.layout
    elif pathname == "/media-posts":
        return media_posts.layout
    elif pathname == "/competitors":
        return competitors.layout
    elif pathname == "/post-performance":
        return post_performance.layout
    elif pathname == "/text-analysis":
        return text.layout
    else:
        return overview.layout


if __name__ == "__main__":
    print("Running in development mode")
    app.run_server(host="0.0.0.0", port=5000, debug=False)

是否有人可以建议什么可能导致问题,请和一种方法,以修复它,而不复制我的所有文件到一个新的文件夹位置?

EN

回答 1

Stack Overflow用户

发布于 2022-04-29 13:09:08

试着用sudo

数独python3 index.py

或sudo python index.py

票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72057731

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档