0

I am trying to import "enum" but I get a import error saying it cant find it. But it is there.

(cvnano) joev2@joev2-desktop:~/pylibfreenect2$ sudo python 
selective_streams.py
Traceback (most recent call last):
File "selective_streams.py", line 8, in 
<module>
    from pylibfreenect2 import Freenect2, 
SyncMultiFrameListener
  File 
"/home/joev2/pylibfreenect2/pylibfreenect2/__i n it__.py", line 15, in 
<module>
   import enum
ImportError: No module named enum

but when I do this it shows its there

(cvnano) joev2@joev2-desktop:~/pylibfreenect2$ python
Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from enum import IntEnum
>>> 

Any Ideas? I am Working in a .virtual environment if that helps.

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
joebob
  • 11
  • 6

1 Answers1

0

Per the virtualenv docs:

"If you directly run a script or the python interpreter from the virtualenv’s bin/ directory (e.g. path/to/ENV/bin/pip or /path/to/ENV/bin/python-script.py) then sys.path will automatically be set to use the Python libraries associated with the virtualenv"

Therefore, if you run set an explicit path to your virtualenv's python executable:

sudo /path/to/ENV/bin/python selective_streams.py

then you'll run your virtualenv's Python with sudo privileges.

There is one caveat, however:

... unlike the activation scripts, the environment variables PATH and VIRTUAL_ENV will not be modified. This means that if your Python script uses e.g. subprocess to run another Python script (e.g. via a #!/usr/bin/env python shebang line) the second script may not be executed with the same Python binary as the first nor have the same libraries available to it. To avoid this happening your first script will need to modify the environment variables in the same manner as the activation scripts, before the second script is executed.

unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677