Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8978727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:41:00+00:00 2026-06-15T19:41:00+00:00

I have a pickled file called classifier.pkl that I am trying to load into

  • 0

I have a pickled file called classifier.pkl that I am trying to load into another module. However, I get an error I don’t understand.

My code to pickle:

features = ['bob','ice','snowing'] #... shortened for exposition's sake
def extract_features(document):
      return  {'contains(%s)'% word: (word in set(document)) 
                 for word in all_together_word_list} 
training_set = classify.util.apply_features(extract_features,tweets[0])
classifier = NaiveBayesClassifier.train(training_set)
cPcikle.dump(open('cocaine_classifier.pkl','wb'))

My code to unpickle:

features, extract_features, classifier = 
         cPickle.load(open('cocaine_classifier.pkl','rb'))

My error:

AttributeError: 'module' object has no attribute 'extract_features'

A while ago I made the .pkl file by pickling three things:

  • features : list
  • extract_features : function
  • classifier : instance of NLTK Naive Bayes Classifier

Puzzlingly, I get the same error with the following code:

x = cPickle.load(open('cocaine_classifier.pkl','rb'))

Why can’t I retrieve three things? Even when I’m not trying to unpack the tuple?

Update

As NPE pointed out the path of the function to be unpickled must exactly match the function into which its being unpickled. I was debugging and Terminal and so from mod import * loads everything into the namespace whereas import mod as m does not.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:41:01+00:00Added an answer on June 15, 2026 at 7:41 pm

    The problem is that when you pickle a function, only the (fully-qualified) name of the function is pickled, not the function itself. This means that you have to have the function definition in place when you’re unpickling.

    Did you by any chance mean to pickle the result of calling extract_features?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that imports data from a pickled file. It works just
I'm trying to load pickled objects in iPython. The error I'm getting is: AttributeError:
I have a fairly large pickled (dict) file in binary format that takes few
I have a pickled object in a file named b1.pkl: $ ls -l b*
I have a large data loaded from a pickled file. The data is a
i have the following code in a module called code_database.py class Entry(): def enter_data(self):
I have been working on a project that dynamically creates a javascript file using
I have a program that wants to be called from the command line many
How do I include a ruby code file, as is, into RDoc? I have
I have a PHP script called customers.php that is passed a parameter via the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.