使用python3.6的Ubuntu中“enum”的导入错误

2024-10-01 04:48:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图导入“枚举”,但我得到一个导入错误,说它找不到它。 但它就在那里。你知道吗

(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

但当我这么做的时候,它显示了它的存在

(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
>>> 

有什么想法吗? 我在一个虚拟的环境中工作,如果这有帮助的话。你知道吗


Tags: infrompyimport错误lineenumstreams
1条回答
网友
1楼 · 发布于 2024-10-01 04:48:06

根据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"

因此,如果运行set显式路径到virtualenv的python可执行文件:

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

然后用sudo权限运行virtualenv的Python。你知道吗

但是,有一个caveat

... 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.

相关问题 更多 >