初学python,pycharm和Spyder哪个好

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了初学python,pycharm和Spyder哪个好相关的知识,希望对你有一定的参考价值。

1. Spyder和anaconde
这两个是孪生兄弟,可以说在anaconda官网上下载,安装好anaconde之后,就已经安装好了
Spyder,不得不说,anaconda一次性下载了很多常用的python包,而且对于包管理也很方便。但是,Anaconda不是
IDE,Spyder是一个IDE,也是我第一个用的python相关的IDE,可是发现调试程序的时候,有很多变量他都不会显示,例如self等,这让
人在debug的时候很痛苦。

2. Pycharm
很强大的python
IDE,上手很快(Spyder同样也上手快),最深刻的体验是,所以的变量都能显示,方便调试,里边还有ipython
notebook,终于不用切换到浏览器中用notebook做实验了。现在一直再用它了,没有用别的IDE。PS.
看到有人在评论区说它运行速度有点慢,我只在Linux下用过,i5, 8G内存,启动的时候稍微有点慢,但是正常运行的时候一点都不慢。

3. Sublime text3
也是特别好用,貌似装插件之后可以直接运行python,但是我只是把他当做文本编辑器来使用,个人感觉它不能被分类为python的IDE(当然,很有可能是我用的不深,没有接触到)。不得不说,用它来写代码还是特别舒服的。尤其是ctrl+p的不同文件跳转,好棒。

上边代表个人观点,提供一点参考,大家喜欢用哪个,还是多尝试下,才知道自己到底适合哪个。我一般用pycharm来debug,当发现程序没有语法和逻辑错误了,再用sublime来扩展下,在terminal下,执行最终写好的程序。以上。
参考技术A 你好,学习Python编程语言,是大家走入编程世界的最理想选择。无论是学习任何一门语言,基础知识,就是基础功非常的重要,找一个有丰富编程经验的老师或者师兄带着你会少走很多弯路, 你的进步速度也会快很多,无论我们学习的目的是什么,不得不说Python真的是一门值得你付出时间去学习的优秀编程语言。在选择培训时一定要多方面对比教学,师资,项目,就业等,慎重选择。本回答被提问者采纳 参考技术B pycharm
、、、

我无法在 pycharm 和 spyder 上运行 streamlit。我在窗口上运行最新的 python 版本。当我尝试代码时,它说语法无效

【中文标题】我无法在 pycharm 和 spyder 上运行 streamlit。我在窗口上运行最新的 python 版本。当我尝试代码时,它说语法无效【英文标题】:I am unable to run streamlit on pycharm and spyder. I am running the latest python version on window.When I try what the code ,it says invalid syntax 【发布时间】:2021-10-06 08:58:45 【问题描述】:

#此代码用于在浏览器中打开streamlit

导入流光 导入 streamlit 作为 st 将熊猫导入为 pd 从 FPL 导入 predict_team,get_overview_data,extract_player_roster, extract_teams_data,extract_player_types 将 matplotlib.pyplot 导入为 plt 将 numpy 导入为 np pd.options.display.float_format = ":,.2f".format

def get_team_limit(max_players_from_team):
    max_players_from_team['ARS'] = int(st.text_input('ARS:', 3))
    max_players_from_team['AVL'] = int(st.text_input('AVL:', 3))
    max_players_from_team['BHA'] = int(st.text_input('BHA:', 3))
    max_players_from_team['BUR'] = int(st.text_input('BUR:', 3))
    max_players_from_team['CHE'] = int(st.text_input('CHE:', 3))
    max_players_from_team['CRY'] = int(st.text_input('CRY:', 3))
    max_players_from_team['EVE'] = int(st.text_input('EVE:', 3))
    max_players_from_team['FUL'] = int(st.text_input('FUL:', 3))
    max_players_from_team['LEE'] = int(st.text_input('LEE:', 3))
    max_players_from_team['LEI'] = int(st.text_input('LEI:', 3))
    max_players_from_team['LIV'] = int(st.text_input('LIV:', 3))
    max_players_from_team['MCI'] = int(st.text_input('MCI:', 3))
    max_players_from_team['MUN'] = int(st.text_input('MUN:', 3))
    max_players_from_team['NEW'] = int(st.text_input('NEW:', 3))
    max_players_from_team['SHU'] = int(st.text_input('SHU:', 3))
    max_players_from_team['SOU'] = int(st.text_input('SOU:', 3))
    max_players_from_team['TOT'] = int(st.text_input('TOT:', 3))
    max_players_from_team['WBA'] = int(st.text_input('WBA:', 3))
    max_players_from_team['WHU'] = int(st.text_input('WHU:', 3))
    max_players_from_team['WOL'] = int(st.text_input('WOL:', 3))

    return max_players_from_team


st.markdown("<h1 style='text-align: center;'>Welcome to FPL TeamMaker</h1>", \
            unsafe_allow_html=True)
st.markdown("<h3 style='text-align: center;'>Use Data Science to build your \
            team and win!</h3>", unsafe_allow_html=True)

transfer = False
wildcard = False
gw = 1
budget = 1000
old_data_weight = 0.4
new_data_weight = 0.6
form_weight = 0.5
max_players_from_team = 
current_team = []
num_transfers = 1


gw = int(st.text_input('Enter the Gameweek you want to make team for:', '1'))
if gw == 1:
    st.write('Starting below, please provide how many players you want from each team.\
        Use this in cases when a particular team does not have a fixture for the week.')
    max_players_from_team = get_team_limit(max_players_from_team)

elif gw > 1 and gw <= 4:
    transfer_or_wildcard = st.radio('Select your mode of team making:', ('Transfer',\
                                'New Team / Wildcard'))
    if transfer_or_wildcard == 'Transfer':
        transfer = True
    else:
        wildcard = True

    old_data_weight = float(st.text_input('Enter the weight you want to give to last \
                                season\'s  data (0-1.0):', 0.4))
    new_data_weight = float(st.text_input('Enter the weight you want to give to current \
                                season\'s  data (0-1.0):', 0.6))
    form_weight = float(st.text_input('Enter the weight you want to give to player form \
                            (0-1.0):', 0.5))
    budget = float(st.text_input('Enter your budget x 10 (For transfers, enter \
                                 the leftover budget using current team):', 1000))

    if transfer:
        num_transfers = int(st.text_input('Enter the number of transfers to be made:', 1))
        overview_data_json = get_overview_data()
        teams_df = extract_teams_data(overview_data_json)
        player_types_df = extract_player_types(overview_data_json)
        player_df = extract_player_roster(overview_data_json, player_types_df, teams_df)
        player_df = player_df[['code', 'first_name', 'second_name', 'team_code']]
        players = st.write('Please look at the list below and enter a comma \
                                 separated list of player codes you have in your team. \
                                 Note that they are ordered alphabetically by team name.', \
                                 player_df)
        try:
            current_team = st.text_input('')
            current_team = list(map(int, current_team.split(',')))
        except:
            st.error('Please enter an input above')

    else:
        st.write('Starting below, please provide how many players you want from each team.\
        Use this in cases when a particular team does not have a fixture for the week.')
        max_players_from_team = get_team_limit(max_players_from_team)

elif gw > 4 and gw <=38:
    transfer_or_wildcard = st.radio('Select your mode of team making:', ('Transfer',\
                                'New Team / Wildcard'))
    if transfer_or_wildcard == 'Transfer':
        transfer = True
    else:
        wildcard = True


    form_weight = float(st.text_input('Enter the weight you want to give to player form \
                            (0-1.0):', 0.5))
    budget = float(st.text_input('Enter your budget x 10 (For transfers, enter \
                                 the leftover budget using current team):', 1000))

    if transfer:
        num_transfers = int(st.text_input('Enter the number of transfers to be made:', 1))
        overview_data_json = get_overview_data()
        teams_df = extract_teams_data(overview_data_json)
        player_types_df = extract_player_types(overview_data_json)
        player_df = extract_player_roster(overview_data_json, player_types_df, teams_df)
        player_df = player_df[['code', 'first_name', 'second_name', 'team_code']]
        players = st.write('Please look at the list below and enter a comma \
                                 separated list of player codes you have in your team. \
                                 Note that they are ordered alphabetically by team name.', \
                                 player_df)
        try:
            current_team = st.text_input('')
            current_team = list(map(int, current_team.split(',')))
        except:
            st.error('Please enter an input above')

    else:
        st.write('Starting below, please provide how many players you want from each team.\
        Use this in cases when a particular team does not have a fixture for the week.')
        max_players_from_team = get_team_limit(max_players_from_team)

if st.button('Get Team'):

    if gw > 38:
        st.error('Enter correct GW')

    team, points, cost = predict_team(transfer, wildcard, gw, budget, old_data_weight, \
                 new_data_weight, form_weight, max_players_from_team, \
                 current_team, num_transfers)
    team['Cost'] /= 10
    team = team.rename(columns = "First": "First Name", "Second": "Second Name")
    if len(team) > 0:
        st.write(team)
        st.write('Total points of whole team:', points)
        st.write('Cost of the team:', cost)
    else:
        st.info('Please use this feature after GW4 has completed')


st.markdown("<h1 style='text-align: center;'>Visualization of Results</h1>", unsafe_allow_html=True)


bot101_points = np.array([0, 84, 133, 180, 222, 294, 349, 401, 470\
, 551, 593, 662, 723, 774, 866, 914, 965, 1028, 1070\
,  1151, 1196, 1268, 1352, 1403, np.nan, np.nan, np.nan, np.nan\
, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan])

average_points = np.array([0, 50, 109, 152, 200, 260, 308, 361, 416\
, 471, 515, 577, 628, 670, 730, 771, 808, 864, 894\
, 968, 1010, 1058, 1115, 1173, np.nan, np.nan, np.nan, np.nan, np.nan\
, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan])

bot101_rank = np.array([0, 0.175178, 0.881887, 0.797683, 1.412642, 1.056323, 0.915314, 1.0164, 0.785028\
, 0.378354, 0.515661, 0.522446, 0.495127, 0.426231, 0.218577, 0.226317, 0.191098, 0.204354, 0.219032\
, 0.302307, 0.318217, 0.224458, 0.183696, 0.275990, np.nan, np.nan, np.nan, np.nan, np.nan\
, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan])

bot101_gwrank = np.array([0, 0.175178, 4.534625, 1.174666, 4.348521, 1.728420, 2.062787, 3.960282, 1.105014\
, 0.247396, 2.6096, 2.559066, 1.815474, 1.603100, 0.178608, 2.406347, 0.969028, 2.743019, 1.780634\
, 2.626326, 2.934196, 0.699079, 0.497828, 5.061059, np.nan, np.nan, np.nan, np.nan, np.nan\
, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan])

bot101_gw_points = np.array([0, 84, 49, 55, 42, 72, 55, 52, 69, 81, 50, 69, 61, 51, 92, 48, 51, 63, \
42, 81, 45, 72, 88, 55, np.nan, np.nan, np.nan, np.nan, np.nan\
, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan])

bot101_gw_avg_points = np.array([0, 50, 59, 43, 48, 60, 48, 53, 55, 55, 44, 62, 51, 42, 60, 41, 37, \
56, 30, 74, 42, 48, 57, 58, np.nan, np.nan, np.nan, np.nan, np.nan\
, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan])

gameweeks = [i for i in range(0, 39)]

ax = plt.gca()
ax.set_xlim(0,39)
plt.plot(gameweeks, bot101_points, label = 'Cumulative Team Points')
plt.plot(gameweeks, average_points, label = 'Cumulative Average Points')
plt.xlabel('Gameweeks')
plt.ylabel('Total Points')
plt.title('Total Points Viewed per Week')
plt.legend()
plt.locator_params(axis="x", nbins=38)
st.pyplot()

ax = plt.gca()
ax.invert_yaxis()
ax.ticklabel_format(useOffset=False, style = 'plain')
plt.locator_params(axis="y", nbins=20)
plt.locator_params(axis="x", nbins=38)

ax.set_xlim(0,39)
plt.plot(gameweeks, bot101_rank, label = 'Overall Rank')
plt.plot(gameweeks, bot101_gwrank, label = 'GW Rank')
plt.xlabel('Gameweeks')
plt.ylabel('Ranking (in millions)')
plt.title('Overall vs GW Rank')
plt.legend()
st.pyplot()

ax = plt.gca()
ax.set_xlim(0,39)
plt.plot(gameweeks, bot101_gw_points, label = 'Team Points per Gameweek')
plt.plot(gameweeks, bot101_gw_avg_points, label = 'Average Points per Gameweek')
plt.xlabel('Gameweeks')
plt.ylabel('Points')
plt.title('Points per Week')
plt.legend()
plt.locator_params(axis="x", nbins=38)


st.pyplot()

#THIS IS HOW THE PROGRAM RESPONDS
#OUTPUT:

#Warning: to view this Streamlit app on a browser, run it with the following
  #command:

    #streamlit run C:/Users/HP/PycharmProjects/pythonProject/app.py [ARGUMENTS]

【问题讨论】:

【参考方案1】:

您的代码运行良好(我在下面附上的本地屏幕截图中运行)。

你没有提到你是如何运行代码的,所以我假设你是通过 spyder 或 pycham 上的运行按钮运行的。所以,基本上这些按钮运行命令“python filename”。虽然在运行之前需要编译一个 stramlit 应用程序,但请转到您的终端并运行命令 streamlit run ***filename.py***

所以基本上代码需要使用 streamlit 命令而不是 python 来运行。希望这会奏效。

【讨论】:

【参考方案2】:

运行这个命令:streamlit run app.py

【讨论】:

一个好的答案将始终包括解释为什么这会解决问题,以便 OP 和任何未来的读者可以从中学习。【参考方案3】:

按照以下步骤操作:

    打开命令提示符 cd(将目录更改为您的项目文件夹) 然后输入streamlit run app.py(用你的python文件名更改app.py)

【讨论】:

以上是关于初学python,pycharm和Spyder哪个好的主要内容,如果未能解决你的问题,请参考以下文章

初学python,pycharm和Spyder哪个好

初学python,pycharm和Spyder哪个好

Python的另一种开发环境--Anaconda中的Spyder

我无法在 pycharm 和 spyder 上运行 streamlit。我在窗口上运行最新的 python 版本。当我尝试代码时,它说语法无效

python用啥软件写代码

初学 Python 需要安装哪些软件?