-5

I am using Kali Linux, and trying to run some Python3 code.

enter image description here

But it always gives me such an error log.

However, latter I get out of that directory and navigate to my home directory, it works again.

enter image description here

I am thinking that maybe it has something to do with my current path.

But how can that influence my import and lead to such an issue?

UPDATE #1

Here I found the solution.

slm
  • 369,824

1 Answers1

1

When you are in the directory /usr/lib/python2.7/dist-packages there is a module called enum:

ls | grep ^enum
enum 

So when your python3 tries to import re, it has a dependency on enum, which it tries to load in it's current directory looking at sys.path, in this contect '' is the current directory. But in that directory it is a python 2.7 module. Which is why you do not see the error when you are in any other directory.

>>> print(sys.path)
['', 
'/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip', 
'/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6', 
'/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib- 
dynload', 
'/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site- 
packages']

So you can update your sys.path or just not work in that python2.7 packages directory with python3.

Joe M
  • 876