1

I managed to break one of my virtual environments. I think I did it by installing pycrypto with pip and uninstalling it with easy_install.

This is what I get when I run python in the venv.

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$

And outside the venv everything works as expected:

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

How can I fix this?

Filip Haglund
  • 13,919
  • 13
  • 64
  • 113
  • Possible duplicate of [Importing installed package from script raises "AttributeError: module has no attribute" or "ImportError: cannot import name"](https://stackoverflow.com/questions/36250353/importing-installed-package-from-script-raises-attributeerror-module-has-no-at) – pppery Aug 19 '19 at 13:49

1 Answers1

3

You should not name your file types.py as there is a standard library module with the same name (import types).

As such, Python tries to import it as part of some standard library code but it now actually imports your local types.py file, not the module it expects.

So the problem should be fixed when you rename types.py to something else.

Simeon Visser
  • 118,920
  • 18
  • 185
  • 180