簡體   English   中英

Ubuntu 終端打開 Python 而不是運行 Python 文件

[英]Ubuntu Terminal Opens Python Instead of Running Python File

我正在嘗試使用python3 index.py從 Ubuntu 終端運行 python 腳本,但 Ubuntu 只是打開 Python 終端而不是運行實際腳本。 此行為僅在最近幾天開始,在此之前代碼按預期運行。

這只發生在一個特定的文件夾中,我相信它與文件夾的虛擬環境(使用 venv 創建)有關。 當虛擬環境未激活時, python3 index.py嘗試運行該文件,我收到ModuleNotFound錯誤。

導致問題的文件夾包含創建儀表板 web 應用程序的文件,並且它們已放入 Docker 容器中,因此我不確定這是否與此有關。

機器:Windows 11

Python:3.8.10

Ubuntu:20.04

問題文件夾內容:

|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 文件的內容:

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)

有沒有人能就可能導致問題的原因提出建議,以及在不將我的所有文件復制到新文件夾位置的情況下解決問題的方法?

試試 sudo

sudo python3 index.py

或者 sudo python index.py

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM