0

I have this piece of code

from module1 import *

feature1() # from module1

I get a NameError exception

NameError: global name 'feature1' is not defined

It works perfectly in python main.py, but when I use pyinstaller to compile, my executable throws the NameError exception. How would I go about fixing this?

Aidan H
  • 124
  • 9

3 Answers3

0
  1. Make sure that module1 exists and defined

  2. Make sure that feature1 exists in module1

  3. Make sure that feature1 is a function, not anything else (like type or object)

  4. If you use a virtual environment, make sure that the package is installed there and

4a. Make sure that you run your script from the virtual environment

Skipper
  • 366
  • 3
  • 6
0

You really shouldn't use import * it makes it so much harder to work out where objects come from - any many linters will simply not work.

Try doing:

from module1 import *
dir()

this will tell you what has been imported and is available to use. If feature1 isn't there then you have your explanation - if it is there you have a more complex journey ahead of you.

dwagon
  • 501
  • 3
  • 9
  • `feature1` does show when in Python, but I don't believe it is being imported into my pyinstaller executable. – Aidan H Mar 06 '19 at 05:22
0

When compiling your script with pyinstaller, use the command pyinstaller -p /Path/To/Your/Module1/Folder main.py

This will add the directory containing your scripts to the PATH variable and will add your module1.py to the compiled exe.

Jack Walsh
  • 562
  • 4
  • 14