打开python文件但正确设置flake时,Flymake配置错误

时间:2017-06-28 18:05:26

标签: flake8 elpy

当我在emacs中打开python文件时,我收到以下错误消息:

  

Flymake:运行时出现配置错误(flake8> .... / xyz_flymake.py)。 Flymake将关闭。

但另一方面,似乎我已经配置了elpy正常工作所需的所有模块:

[Serializable]
public class MovieDialog : IDialog<object>
{
    public async Task StartAsync(IDialogContext context)
    {
        context.Wait(MessageReceivedAsync);

        //return Task.CompletedTask;
    }





    public async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
    {
        Activity activity = (Activity)context.Activity;
        string szMovieDate = "";
        string szMovieLanguage = "";
        string szMovieName = "";
        context.ConversationData.TryGetValue(ContextConstants.MovieDateKey, out szMovieDate);
        context.ConversationData.TryGetValue(ContextConstants.LanguageKey, out szMovieLanguage);


        if (!(context.ConversationData.TryGetValue(ContextConstants.MovieNameKey, out szMovieName)))
        {
            var reply = context.MakeMessage();
            reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
            reply.Attachments = GetCardsAttachments(context);
            await context.PostAsync(reply);
        }
        else
        {
            context.ConversationData.SetValue(ContextConstants.MovieNameKey, Convert.ToString(activity.Text));
            await context.Forward(new ConfirmationDialog(), this.ResumeAfterConfirmationDialog, activity, CancellationToken.None);
            //await context.PostAsync(activity);
        }

        context.Wait(this.MessageReceivedAsync);
        //Below is Test line
        //await context.PostAsync("List of movies in " + Convert.ToString(activity.Text));
        //If Context Forward is there then ContextWait is not needed. 
        //context.Wait(MessageReceivedAsync);
    }

    private static IList<Attachment> GetCardsAttachments(IDialogContext context)
    {
        List<Attachment> oImageAttachment = new List<Attachment>();

        Dictionary<string, string> lstmovie = new Dictionary<string, string>();
        lstmovie.Add("Movie1", @"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg");
        lstmovie.Add("Movie2", @"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg");
        lstmovie.Add("Movie3", @"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg");
        lstmovie.Add("Movie4", @"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg");
        lstmovie.Add("Movie5", @"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg");

        foreach (KeyValuePair<string, string> movielist in lstmovie)
        {
            oImageAttachment.Add(
                GetHeroCard(
                    movielist.Key,
                    new CardImage(url: movielist.Value),
                    new CardAction(ActionTypes.PostBack, "Book","",movielist.Key))
            );
        }

        context.ConversationData.SetValue(ContextConstants.MovieNameKey, "");
        return oImageAttachment;
    }

    private static Attachment GetHeroCard(string title, CardImage cardImage, CardAction cardAction)
    {
        var heroCard = new HeroCard
        {
            Title = title,
            Images = new List<CardImage>() { cardImage },
            Buttons = new List<CardAction>() { cardAction },
        };

        return heroCard.ToAttachment();
    }

    private async Task ResumeAfterConfirmationDialog(IDialogContext context, IAwaitable<object> result)
    {
        // Store the value that NewOrderDialog returned. 
        // (At this point, new order dialog has finished and returned some value to use within the root dialog.)
        Activity activity = (Activity)context.Activity;
        var optionSelected = activity.Text;

        //await context.PostAsync(Convert.ToString(resultFromNewOrder));

        // Again, wait for the next message from the user.
        context.Done(optionSelected);
    }
}

如何解决此问题?

1 个答案:

答案 0 :(得分:3)

目前还不清楚配置错误是什么。您可能遇到许多问题之一。

  1. 您似乎想要使用Python 3.5,但没有明确指示运行Python Flake8的版本。可能是elpy检测到不匹配并拒绝使用Flake8,因为它不会为您提供任何有用的信息。 (Flake8必须安装在代码要运行的相同版本的Python上。)

  2. Elpy似乎坚持您使用virtualenv或将~/.local/bin/添加到PATH。我建议两者兼顾。

    您可以通过virtualenv ~/.elpy-venv创建virtualenv并使用source ~/.elpy-venv/bin/activate激活它。

    您可以编辑Shell的配置文件(例如~/.bashrc~/.bash_profile~/.zshrc等)以执行export PATH="$PATH:~/.local/bin"