我的 main.py 脚本是 pycharm IDE 中的 运行 但不是来自终端。为什么会这样?
My main.py script is running in pycharm IDE but not from terminal. Why is this so?
当我想在终端中 运行 我的 python main.py 脚本时,它会引发以下异常:
Traceback (most recent call last):
File "main.py", line 14, in <module>
from typeform_api import get_data # Step 1)
File "/Users/philipp/Documents/PycharmProjects/Wegekompass/typeform_api.py", line 9, in <module>
import pandas as pd # For creating a dataframe for the data
ModuleNotFoundError: No module named 'pandas'
我已经阅读了这两个问题的答案,但找不到任何解决方案:
这是我的main.py方法:
"""
Logic Flow of main.py:
1) Fetch Data with API
2) Preprocess the Data
3) Start topic modeling
4) Create report and include data
5) send report via e-mail to user
"""
import os
import sys
from typeform_api import get_data # Step 1)
from preprocessing import preprocess_data # Step 2)
from topic_modeling import create_topic_model # Step 3)
from create_report import * # Step 4)
from send_report import send_report # Step 5)
if __name__ == '__main__':
# 1) Fetch Data with Typeform API:
alle_antworten_txt = get_data()[3]
projektname = get_data()[0]
projekt_id = get_data()[1]
user_email = get_data()[2]
heute_txt_short = get_data()[3][4]
heute_txt_long = get_data()[3][1:3]
heute_txt_long_joined = ". ".join(heute_txt_long)
morgen_txt_short = get_data()[3][8]
morgen_txt_long = get_data()[3][5:7]
morgen_txt_long_joined = ". ".join(morgen_txt_long)
erfolgshebel_txt_short = get_data()[3][17]
erfolgshebel_txt_long = get_data()[3][14:16]
erfolgshebel_txt_long_joined = ". ".join(erfolgshebel_txt_long)
staerken_txt = get_data()[3][12:13]
staerken_txt_joined = ". ".join(staerken_txt)
schwaechen_txt = get_data()[3][10:11]
schwaechen_txt_joined = ". ".join(schwaechen_txt)
reflexion_txt = get_data()[3][9]
etappe1_fachlich_txt = get_data()[3][18]
etappe1_kulturell_txt = get_data()[3][19]
etappe2_fachlich_txt = get_data()[3][20]
etappe2_kulturell_txt = get_data()[3][21]
etappe3_fachlich_txt = get_data()[3][22]
etappe3_kulturell_txt = get_data()[3][23]
weg_von_energie = get_data()[4][0]
hin_zu_energie = get_data()[4][1]
umsetzungsenergie = get_data()[4][2]
# 2) Preprocess and tokenize fetched Data:
alle_antworten_txt_tokens = preprocess_data(alle_antworten_txt)[1]
heute_txt_long_tokens = preprocess_data(heute_txt_long)[1]
morgen_txt_long_tokens = preprocess_data(morgen_txt_long)[1]
# 3) Start NLP analysis:
# answer_analysis = create_topic_model(alle_antworten_txt_tokens)[1]
try:
heute_wortwolke = create_topic_model(heute_txt_long_tokens)[2]
heute_wortwolke.to_file(os.getcwd() + "/Grafiken/Wortwolken/heute_wortwolke"+projekt_id+".png")
morgen_wortwolke = create_topic_model(morgen_txt_long_tokens)[2]
morgen_wortwolke.to_file(os.getcwd() + "/Grafiken/Wortwolken/morgen_wortwolke"+projekt_id+".png")
except ValueError:
print("There is not enough word input, LDA analysis raises ValueError")
sys.exit(0)
# 4) Create final report:
try:
final_report = create_final_report(heute_txt_short,
morgen_txt_short,
erfolgshebel_txt_short,
heute_txt_long_joined,
morgen_txt_long_joined,
erfolgshebel_txt_long_joined,
staerken_txt_joined,
schwaechen_txt_joined,
reflexion_txt,
os.getcwd() + "/Grafiken/Wortwolken/heute_wortwolke"+projekt_id+".png",
os.getcwd() + "/Grafiken/Wortwolken/morgen_wortwolke"+projekt_id+".png",
etappe1_fachlich_txt,
etappe1_kulturell_txt,
etappe2_fachlich_txt,
etappe2_kulturell_txt,
etappe3_fachlich_txt,
etappe3_kulturell_txt,
weg_von_energie,
hin_zu_energie,
umsetzungsenergie,
projektname,
projekt_id)
except FileNotFoundError:
print("There is not enough word input, wordcloud can't be computed so FileNotFoundError is raised")
sys.exit(0)
# 5) Send final report:
try:
send_report(final_report, user_email, projektname, projekt_id)
except NameError:
print("variable final_report not defined due missing wordclouds")
sys.exit(0)
# 6) Check if program reached its end:
print("If this gets print, the report was send successfully.")
这是我的项目文件夹的结构:
├── Dockerfile
├── Error-Handling.md
├── Grafiken
│ ├── 1Etappe_Card-min.png
│ ├── 2Etappe_Card-min.png
│ ├── 3Etappe_Card-min.png
│ ├── AD_Logo-min.png
│ ├── Dynamik_Abflug-min.png
│ ├── Dynamik_Anflug-min.png
│ ├── Dynamik_Hoehenflug-min.png
│ ├── Dynamik_Parabelflug-min.png
│ ├── Dynamik_Sinkflug-min.png
│ ├── Dynamik_Steigflug-min.png
│ ├── Dynamik_Talflug-min.png
│ ├── Dynamik_Tiefflug-min.png
│ ├── Entwicklung_Card-min.png
│ ├── Erfolgshebel_Card-min.png
│ ├── Framework_Abflug-min.png
│ ├── Framework_Anflug-min.png
│ ├── Framework_Hoehenflug-min.png
│ ├── Framework_Parabelflug-min.png
│ ├── Framework_Sinkflug-min.png
│ ├── Framework_Steigflug-min.png
│ ├── Framework_Talflug-min.png
│ ├── Framework_Tiefflug-min.png
│ ├── Heute_Card-min.png
│ ├── Morgen_Card-min.png
│ ├── Reflexion_Card-min.png
│ ├── Strength_Card-min.png
│ ├── Weakness_Card-min.png
│ ├── Wegekompass_Hero-min.png
│ └── Wortwolken
├── PDF_Reports
├── README.md
├── __pycache__
│ ├── config.cpython-38.pyc
│ ├── create_report.cpython-38.pyc
│ ├── main.cpython-38.pyc
│ ├── preprocessing.cpython-38.pyc
│ ├── send_report.cpython-38.pyc
│ ├── topic_modeling.cpython-38.pyc
│ └── typeform_api.cpython-38.pyc
├── config.py
├── create_report.py
├── html_files
│ └── E_Mail_Template.html
├── main.py
├── preprocessing.py
├── requirements.txt
├── send_report.py
├── topic_modeling.py
├── typeform_api.py
└── venv
├── (...)
如我所说 - main.py 脚本 运行 在 pycharm IDE 中,但不是来自终端。
如何从终端 运行 我的脚本?
看起来您正在使用 venv,
你在 运行 你的脚本之前激活它了吗?
对于 Linux/Mac,您可以执行以下操作:
. venv/bin/activate
对于 windows 你应该使用:
source venv/Scripts/activate
激活虚拟环境后,您可以安装软件包:
pip install -r requirements.txt
当我想在终端中 运行 我的 python main.py 脚本时,它会引发以下异常:
Traceback (most recent call last):
File "main.py", line 14, in <module>
from typeform_api import get_data # Step 1)
File "/Users/philipp/Documents/PycharmProjects/Wegekompass/typeform_api.py", line 9, in <module>
import pandas as pd # For creating a dataframe for the data
ModuleNotFoundError: No module named 'pandas'
我已经阅读了这两个问题的答案,但找不到任何解决方案:
这是我的main.py方法:
"""
Logic Flow of main.py:
1) Fetch Data with API
2) Preprocess the Data
3) Start topic modeling
4) Create report and include data
5) send report via e-mail to user
"""
import os
import sys
from typeform_api import get_data # Step 1)
from preprocessing import preprocess_data # Step 2)
from topic_modeling import create_topic_model # Step 3)
from create_report import * # Step 4)
from send_report import send_report # Step 5)
if __name__ == '__main__':
# 1) Fetch Data with Typeform API:
alle_antworten_txt = get_data()[3]
projektname = get_data()[0]
projekt_id = get_data()[1]
user_email = get_data()[2]
heute_txt_short = get_data()[3][4]
heute_txt_long = get_data()[3][1:3]
heute_txt_long_joined = ". ".join(heute_txt_long)
morgen_txt_short = get_data()[3][8]
morgen_txt_long = get_data()[3][5:7]
morgen_txt_long_joined = ". ".join(morgen_txt_long)
erfolgshebel_txt_short = get_data()[3][17]
erfolgshebel_txt_long = get_data()[3][14:16]
erfolgshebel_txt_long_joined = ". ".join(erfolgshebel_txt_long)
staerken_txt = get_data()[3][12:13]
staerken_txt_joined = ". ".join(staerken_txt)
schwaechen_txt = get_data()[3][10:11]
schwaechen_txt_joined = ". ".join(schwaechen_txt)
reflexion_txt = get_data()[3][9]
etappe1_fachlich_txt = get_data()[3][18]
etappe1_kulturell_txt = get_data()[3][19]
etappe2_fachlich_txt = get_data()[3][20]
etappe2_kulturell_txt = get_data()[3][21]
etappe3_fachlich_txt = get_data()[3][22]
etappe3_kulturell_txt = get_data()[3][23]
weg_von_energie = get_data()[4][0]
hin_zu_energie = get_data()[4][1]
umsetzungsenergie = get_data()[4][2]
# 2) Preprocess and tokenize fetched Data:
alle_antworten_txt_tokens = preprocess_data(alle_antworten_txt)[1]
heute_txt_long_tokens = preprocess_data(heute_txt_long)[1]
morgen_txt_long_tokens = preprocess_data(morgen_txt_long)[1]
# 3) Start NLP analysis:
# answer_analysis = create_topic_model(alle_antworten_txt_tokens)[1]
try:
heute_wortwolke = create_topic_model(heute_txt_long_tokens)[2]
heute_wortwolke.to_file(os.getcwd() + "/Grafiken/Wortwolken/heute_wortwolke"+projekt_id+".png")
morgen_wortwolke = create_topic_model(morgen_txt_long_tokens)[2]
morgen_wortwolke.to_file(os.getcwd() + "/Grafiken/Wortwolken/morgen_wortwolke"+projekt_id+".png")
except ValueError:
print("There is not enough word input, LDA analysis raises ValueError")
sys.exit(0)
# 4) Create final report:
try:
final_report = create_final_report(heute_txt_short,
morgen_txt_short,
erfolgshebel_txt_short,
heute_txt_long_joined,
morgen_txt_long_joined,
erfolgshebel_txt_long_joined,
staerken_txt_joined,
schwaechen_txt_joined,
reflexion_txt,
os.getcwd() + "/Grafiken/Wortwolken/heute_wortwolke"+projekt_id+".png",
os.getcwd() + "/Grafiken/Wortwolken/morgen_wortwolke"+projekt_id+".png",
etappe1_fachlich_txt,
etappe1_kulturell_txt,
etappe2_fachlich_txt,
etappe2_kulturell_txt,
etappe3_fachlich_txt,
etappe3_kulturell_txt,
weg_von_energie,
hin_zu_energie,
umsetzungsenergie,
projektname,
projekt_id)
except FileNotFoundError:
print("There is not enough word input, wordcloud can't be computed so FileNotFoundError is raised")
sys.exit(0)
# 5) Send final report:
try:
send_report(final_report, user_email, projektname, projekt_id)
except NameError:
print("variable final_report not defined due missing wordclouds")
sys.exit(0)
# 6) Check if program reached its end:
print("If this gets print, the report was send successfully.")
这是我的项目文件夹的结构:
├── Dockerfile
├── Error-Handling.md
├── Grafiken
│ ├── 1Etappe_Card-min.png
│ ├── 2Etappe_Card-min.png
│ ├── 3Etappe_Card-min.png
│ ├── AD_Logo-min.png
│ ├── Dynamik_Abflug-min.png
│ ├── Dynamik_Anflug-min.png
│ ├── Dynamik_Hoehenflug-min.png
│ ├── Dynamik_Parabelflug-min.png
│ ├── Dynamik_Sinkflug-min.png
│ ├── Dynamik_Steigflug-min.png
│ ├── Dynamik_Talflug-min.png
│ ├── Dynamik_Tiefflug-min.png
│ ├── Entwicklung_Card-min.png
│ ├── Erfolgshebel_Card-min.png
│ ├── Framework_Abflug-min.png
│ ├── Framework_Anflug-min.png
│ ├── Framework_Hoehenflug-min.png
│ ├── Framework_Parabelflug-min.png
│ ├── Framework_Sinkflug-min.png
│ ├── Framework_Steigflug-min.png
│ ├── Framework_Talflug-min.png
│ ├── Framework_Tiefflug-min.png
│ ├── Heute_Card-min.png
│ ├── Morgen_Card-min.png
│ ├── Reflexion_Card-min.png
│ ├── Strength_Card-min.png
│ ├── Weakness_Card-min.png
│ ├── Wegekompass_Hero-min.png
│ └── Wortwolken
├── PDF_Reports
├── README.md
├── __pycache__
│ ├── config.cpython-38.pyc
│ ├── create_report.cpython-38.pyc
│ ├── main.cpython-38.pyc
│ ├── preprocessing.cpython-38.pyc
│ ├── send_report.cpython-38.pyc
│ ├── topic_modeling.cpython-38.pyc
│ └── typeform_api.cpython-38.pyc
├── config.py
├── create_report.py
├── html_files
│ └── E_Mail_Template.html
├── main.py
├── preprocessing.py
├── requirements.txt
├── send_report.py
├── topic_modeling.py
├── typeform_api.py
└── venv
├── (...)
如我所说 - main.py 脚本 运行 在 pycharm IDE 中,但不是来自终端。
如何从终端 运行 我的脚本?
看起来您正在使用 venv, 你在 运行 你的脚本之前激活它了吗?
对于 Linux/Mac,您可以执行以下操作:
. venv/bin/activate
对于 windows 你应该使用:
source venv/Scripts/activate
激活虚拟环境后,您可以安装软件包:
pip install -r requirements.txt