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



我试图从Ubuntu终端与python3 index.py运行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)

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

try with sudo

sudo python3 .py

或python目录

最新更新