我成功地破坏了我的一个虚拟环境。我想我是通过使用 pip
安装 pycrypto
并使用 easy_install
卸载它来做到的。
这是我在 venv 中运行 python
时得到的结果。
filip@dratmac:~/PycharmProjects/Project-Marketplace2/backend/odb/helper_objects$ python
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 62, in <module>
import os
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 49, in <module>
import posixpath as path
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py", line 17, in <module>
import warnings
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/warnings.py", line 8, in <module>
import types
File "types.py", line 1, in <module>
import json
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 108, in <module>
from .decoder import JSONDecoder
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 3, in <module>
import re
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 280, in <module>
import copy_reg
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy_reg.py", line 7, in <module>
from types import ClassType as _ClassType
ImportError: cannot import name ClassType
filip@dratmac:~/PycharmProjects/Project-Marketplace2/backend/odb/helper_objects$
在 venv 之外,一切都按预期工作:
Last login: Tue Apr 7 22:30:08 on ttys005
filip@dratmac:~$ python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
我该如何解决这个问题?
最佳答案
您不应将文件命名为 types.py
,因为有一个具有相同名称的标准库模块(导入类型
)。
因此,Python 尝试将其作为某些标准库代码的一部分导入,但它现在实际上导入本地 types.py
文件,而不是它期望的模块。
因此,当您将 types.py
重命名为其他名称时,问题应该得到解决。
关于python - 成功打破了我的venv;可以修复吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29501029/