sphchow
sphchow

Reputation: 145

Python import enum error

Having trouble using Enum. Running Python 2.7 on Linux Debian Distribution.
Installed enum package as well as enum34 package for older Python version compatibility.

When I try to import enum with this command in my python module:

from enum import Enum

I get the error:

from enum import Enum
ImportError: No module named enum

I've tried using:

import enum

and

import enum34

with no luck... Getting errors respectively:

ImportError: No module named enum

and

ImportError: No module named enum34

The way I'm trying to use Enum is:

class Callable_Options(Enum):
     function_callable   = 0
     help_param_callable = 1
     help_str_callable   = 2

But my module errors before this.

Any idea how to get Enum working?

Thanks.

EDIT:

Note that I had to change my class to inherit the object

class Callable_Options(IntEnum):

instead of

class Callable_Options(Enum):

To be able to use the attributes to index a list

Upvotes: 4

Views: 9227

Answers (1)

flamenco
flamenco

Reputation: 2840

Need to find the path where enum gets installed. Try this:

import os
path = os.path.dirname(<somemodule>.__file__)
print path

You can use math module for <somemodule> to find the path for your packages. On Mac , usually, path = /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ Browse to that director and look for enum. If it is not there, find out where pip installs packages on your machine and add that path to PYTHONPATH.

Upvotes: 2

Related Questions