我成功打破了我的一个虚拟环境。我想我是通过pycrypto
安装pip
并使用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.
>>>
我该如何解决这个问题?
答案 0 :(得分:3)
您不应将文件命名为types.py
,因为标准库模块具有相同的名称(import types
)。
因此,Python尝试将其作为一些标准库代码的一部分导入,但它现在实际上导入了本地types.py
文件,而不是它期望的模块。
因此,当您将types.py
重命名为其他内容时,应解决此问题。