title: ImputError: cannot import name "function" from "module.py"
body: <p>In Jupyter Notebook:
  repo:</p>
  <ul>
  <li>module: featurestorehouse.py</li>
  <li>main: preprocessing.ipynb</li>
  </ul>
  <p>I have several functions in featurestorehouse.py, I need to import most of them, and some of them, particularly the ones I wrote earlier in time, work when I import them. However, the more recent ones don't want to be imported as it gives an ImputError.</p>
  <p>I checked and changed where necessary, the necessary modules are imported in the module file, I tried putting the imports specific to a function within the function definition - which didn't fix anything, and I tried to not import the functions separately but adding 'fs.' in front of each to reference featurestorehouse as fs.</p>
  <p>The function and module:</p>
  <pre><code># # Feature Engineering #
  
  import pandas as pd
  import numpy as np
  import spacy
  import re
  import string
  from statistics import mean
  from collections import Counter 
  </code></pre>
  <p>Some of the functions that do not work:</p>
  <pre><code># Phrasal complexity
  ## reference to Martinez (2018)
  
  def nr_np(series):
      &quot;&quot;&quot;Calculates nr of noun chunks in the texts.&quot;&quot;&quot;
      nlp = spacy.load(&quot;en_core_web_sm&quot;)
      text = nlp(series)
      nps = []
      for nc in text.noun_chunks:
          nps.append(np)
      return len(nps)
  
  def count_np(df, word_count_column, np_count_column):
      &quot;&quot;&quot;Divides number of words by number of noun phrases.&quot;&quot;&quot;
      try:
          rel_np = df[word_count_column]/df[np_count_column]
          return rel_np
      except 'ZeroDivisionError':
          return '0'
  
  def count_np_words(df, np_count_column, word_count_column):
      &quot;&quot;&quot;Divides number of noun phrases by number of words.&quot;&quot;&quot;
      try:
          rel_np = df[np_count_column]/df[word_count_column]
          return rel_np
      except 'ZeroDivisionError':
          return '0'
  </code></pre>
  <p>How I tried to implement them in my main notebook:</p>
  <pre><code># Adding Custom Feature Columns
  from featurestorehouse import avg_sentlength, avg_wordlength, nr_deps, count_deps, nr_verbs, count_verbs, nr_words, nr_sents, normalize, normalize_fix, nr_np, count_np, count_np_words, nr_clauses, rel_nr_clauses, rel_nr_words_clauses, unique_words, lexical_variety
  
  ## extract relevant column as series
  series = df['fulltext'].astype(str)
  
  # Sentence Complexity
  
  ## sentence length
  df['sentence_cnt'] = series.apply(lambda x: nr_sents(x))
  
  ## average sentence length
  df['avg_sentlength'] = series.apply(lambda x: avg_sentlength(x))
  
  
  ## POS distributions
  ### extract relevant column as series
  series = df['POS'].astype(str)
  
  ### apply function
  df['VERB_cnt'] = series.apply(lambda x: nr_verbs(x))
  fs.count_verbs(df, 'TAG', 'VERB_cnt')
  
  
  # Phrasal Complexity
  
  ## NP distributions
  ### extract relevant column as series
  series = df['fulltext'].astype(str)
  
  ### apply function
  df['NP_cnt'] = series.apply(lambda x: nr_np(x))
  df['np_rel_cnt'] = count_np(df, 'word_cnt', 'NP_cnt')
  df['np_rel_word_cnt'] = count_np_words(df, 'NP_cnt', 'word_cnt')
  </code></pre>
  <p>The last set underneath &quot;### apply function&quot; gives an error when I import featurestorehouse.py as fs and add fs. to each function in the main notebook (obviously it doesn't get to this point when I'm importing each function separately from featurestorehouse.py).</p>
  <p>The error:</p>
  <pre><code>ImportError                               Traceback (most recent call last)
  &lt;ipython-input-18-8ad058b0250d&gt; in &lt;module&gt;
        1 # Adding Custom Feature Columns
  ----&gt; 2 from featurestorehouse import avg_sentlength, avg_wordlength, nr_deps, count_deps, nr_verbs, count_verbs, nr_words, nr_sents, normalize, normalize_fix, nr_np, count_np, count_np_words, nr_clauses, rel_nr_clauses, rel_nr_words_clauses, unique_words, lexical_variety
        3 
        4 ## extract relevant column as series
        5 series = df['fulltext'].astype(str)
  
  ImportError: cannot import name 'nr_np' from 'featurestorehouse' (C:\Users\tdems\Jupyter\CEFR_AES_dissertation\featurestorehouse.py)
  </code></pre>
  <p>Does anyone know what's up with this? There's no circular dependencies involved as far as I know. There's a lot of other notebooks in the repo but that's never been a problem up till now.</p>